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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I declare a type of database

Status
Not open for further replies.

royaltg

IS-IT--Management
Jul 24, 2002
15
0
0
I am trying to access records from my tables using the currentDB and recordsets, but when I try to dim a variable as type Database I get a compile error.

Here is the code and error message --

Code:

Dim DB as Database

Error Message:

Compile Error
User-defined type not defined

Any help would be appreciated.
 
Hi!

Dim db as Database is DAO, which means VBA coding for Access 97. Never versions use ADO, which has another syntax.

To still use DAO, go to the modules, the Tools menu and References.

Find Microsoft DAO Object Library and check it, and then...

Roy-Vidar
 
Thanks for the info. I am using Access 2002. What is the syntax and entries I need to make in order to use the database data type?
 
Hi again!

To use DAO code (dim db as database) all you have to do is what I stated in the previous post.

To jump to ADO the whole process is a litle different. I'll give an excample of opening a recordset for changing:

sub test()
dim rs as recordset
dim sSql as string
set rs=new adodb.recordset
with rs
.cursortype=adopendynamic
.loctype=adlockoptimistic
.activeconnection=currentproject.connection
.open "Select * from tbltest",options:=adcmdtext
if not .bof then
' perform some actions
else
msgbox "Couldn't find any records!"
end if
.close
end with
set rs=nothing
end sub

So - you don't use the database data type in ADO, but as mentioned, you can still perfectly well use DAO by checking the Microsoft DAO Object Library in the Tools | References thingie.

HTH Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top