Programming Syntax

  • Thread starter Thread starter Clint Liezert
  • Start date Start date
C

Clint Liezert

I am getting frustrated beyond imagination !!
I am using Windows XP and Access 2002

I have a table in my database named "Codes". I can use
the following code:

Dim myDb As Database
Set myDb = CurrentDb
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
For Each obj In dbs.AllTables
' Print name of obj.
Debug.Print obj.Name
Next obj

And all of the tables, including "Codes" is listed in
the immediate window. But if I try the following code:

Dim myDb As Database
Set myDb = CurrentDb
Dim rstCodes As Recordset
Set rstCodes = myDb.OpenRecordset(Codes)

The system responds that it can't find the input table
or query. I have changed the syntax everyway I can think
of and the only thing that changes is the error message.
It appears that the system doesn't recognize the table or
it is out of the path or whatever. I have used the same
syntax in other applications in earlier versions of
Access. They work in this version as well but I am
obviously overlooking something. Any help would be
GREATLY appreciated.
 
Set rstCodes = myDb.OpenRecordset("Codes")

When you don't put quotes around it, Access assumes it's a variable, and you
haven't declared a variable Code, nor assigned it a value.
 
-----Original Message-----
Set rstCodes = myDb.OpenRecordset("Codes")

When you don't put quotes around it, Access assumes it's a variable, and you
haven't declared a variable Code, nor assigned it a value.


--
Doug Steele, Microsoft Access MVP






.
I have tried that as well ... in fact that was my first
syntax. With the quotes I get a "type mismatch" error.
 
You didn't say where you got the error, but are you sure you've set a
reference to DAO? By default, XP uses AD, and your code may not be able to
distinguish between the two ...:

Dim rst As ADODB.Recordset
Dim dbs As DAO.Database
 
-----Original Message-----
You didn't say where you got the error, but are you sure you've set a
reference to DAO? By default, XP uses AD, and your code may not be able to
distinguish between the two ...:

Dim rst As ADODB.Recordset
Dim dbs As DAO.Database
.




.
Thanks for the try Scott but it makes no difference. I
get the error as soon as the line with "set rstCodes"
tries to execute.
 
* Make sure Microsoft DAO 3.6 Library in included in the
References.

* Try:

Dim myDb As Database
Dim rstCodes As DAO.Recordset

Set myDb = CurrentDb
Set rstCodes = myDb.OpenRecordset("Codes")

HTH
Van T. Dinh
MVP (Access)
 
Back
Top