A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help with SELECT Statement Please...



 
 
Thread Tools Display Modes
  #1  
Old June 14th, 2004, 02:31 PM
Peter
external usenet poster
 
Posts: n/a
Default Help with SELECT Statement Please...

Hi
I'm still learning access and am trying some of the native
coding. The snippet below is the code behind a command
button on a form. All the database, table and field names
are okay and have been checked against the source but
everytime I run it I'm getting a type 13 error. Does
anyone know what I'm doing wrong?

Thanks in advance for any help - this is really driving me
crazy as I've compared it to various statements within
Access Help and still can't see anything wrong.

Peter

PS SELECT line is continuous but has been split by the
posting system so it shouldn't have an underscore after
the FROM statement.

Sub Command0_Click()
Dim dbsmgrs As Database
Dim mgrs2 As Recordset
Set dbsmgrs = OpenDatabase("TestTest.mdb")
Set mgrs2 = dbsmgrs.OpenRecordset("SELECT ManagerName FROM
Managers", dbReadOnly)
recsfound = mgrss.RecordCount
MsgBox (recsfound)

  #2  
Old June 14th, 2004, 03:23 PM
Dirk Goldgar
external usenet poster
 
Posts: n/a
Default Help with SELECT Statement Please...

"Peter" wrote in message

Hi
I'm still learning access and am trying some of the native
coding. The snippet below is the code behind a command
button on a form. All the database, table and field names
are okay and have been checked against the source but
everytime I run it I'm getting a type 13 error. Does
anyone know what I'm doing wrong?

Thanks in advance for any help - this is really driving me
crazy as I've compared it to various statements within
Access Help and still can't see anything wrong.

Peter

PS SELECT line is continuous but has been split by the
posting system so it shouldn't have an underscore after
the FROM statement.

Sub Command0_Click()
Dim dbsmgrs As Database
Dim mgrs2 As Recordset
Set dbsmgrs = OpenDatabase("TestTest.mdb")
Set mgrs2 = dbsmgrs.OpenRecordset("SELECT ManagerName FROM
Managers", dbReadOnly)
recsfound = mgrss.RecordCount
MsgBox (recsfound)


The odds are that your code isn't really in error at all, but rather
that you simply need to specify that the Recordset object you're
declaring is a DAO recordset, not an ADODB recordset. I'm assuming you
have a reference set to the DAO object library, because your would get
an "undefined type" error on "Dim dbsmgrs As Database" if you didn't,
but I guess you also have a reference set to the ADO library, which also
defines a Recordset object. Try changing your declarations to
disambiguate them, as follows:

Dim dbsmgrs As DAO.Database
Dim mgrs2 As DAO.Recordset

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:58 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.