Help with SELECT Statement Please...

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

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)
 
Peter said:
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
 
Back
Top