Newbie - "dim db as database" gives syntax error

G

Guest

I'm trying to add a new record to a table from data selected in a form in VB.

I can successfully select entries from 2 lists. I now want to add those
selections to as a new record in an existing schedule table.

When using example code in my AddSchedButton_Click sub such as:

Dim db as Database
Dim rs as Recordset
Set db = CurrentDB()

to prepare to open the sched table to add the record to, I get a syntax
error for the word "Database."

"Database" is not an available keyword in the list when I enter "Dim db As"

I'm using Access 2000 with VB 6.3.
 
J

John Vinson

Dim db as Database
Dim rs as Recordset
Set db = CurrentDB()

to prepare to open the sched table to add the record to, I get a syntax
error for the word "Database."

"Database" is not an available keyword in the list when I enter "Dim db As"

With the VBA editor open, select Tools... References.

A2002 defaults to using the ADO library (Microsoft ActiveX Data
Objects); the older (and arguably better fit for Access apps) DAO
library - which *has* a Database object type - isn't checked.

Scroll down the list of libraries and find Microsoft DAO 3.6 Object
Library and check it. If you're not using any ADO objects, *uncheck*
the ActiveX Data Objects reference - both ADO and DAO have Recordset
objects, but they are *different* objects. If you leave both
references checked (or, best, even if you don't!), be sure to

Dim db As DAO.Database
Dim rs As DAO.Recordset

to prevent ambiguity.

John W. Vinson[MVP]
 
G

Guest

Bill and John-

Thank you both. That works!

John Vinson said:
With the VBA editor open, select Tools... References.

A2002 defaults to using the ADO library (Microsoft ActiveX Data
Objects); the older (and arguably better fit for Access apps) DAO
library - which *has* a Database object type - isn't checked.

Scroll down the list of libraries and find Microsoft DAO 3.6 Object
Library and check it. If you're not using any ADO objects, *uncheck*
the ActiveX Data Objects reference - both ADO and DAO have Recordset
objects, but they are *different* objects. If you leave both
references checked (or, best, even if you don't!), be sure to

Dim db As DAO.Database
Dim rs As DAO.Recordset

to prevent ambiguity.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top