Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DAO 3.6 now running but

Status
Not open for further replies.

newboy18

MIS
Apr 11, 2003
45
GB
I want to let a variable = the contents of a record, in a table.
My table is called "Table2".
I think I am getting confused between recordsets and records.
So far I have:
Dim bd as Database
Dim rec as Recordset
Set db =CurrentDB
Set rec = OpenRecordset("Table2")
Msgbox rec

When I run it it fails at "Set rec" with Type mismatch.
 
Hi

A couple of things:

1) You've declared bd as a Database variable but then set db=CurrentDb in your code.

2) The correct syntax for that line it's failing on is:
Set rec = db.Openrecordset("Table2",dbOpenDynaset)

The "dbOpenDynaset" is only one option out of a total of 4 choices. See the online help for more info here.

It is also important that you close your recordsets in code:
For example:

rec.Close
rec = Nothing

NSS
 
Follow the previous advice, but.

The error is, typically, due to not explicitly defining the variables/objects since in Access 2000 and above there are multiple recordset objects - DAO and ADO. Also, make sure you have a reference set to one of the DAO libraries.

Dim db as DAO.Database
Dim rec as DAO.Recordset
Set db =CurrentDB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top