Error Message "User-defined type not defined"

A

Anne

I get this error message when running a module, on the
line "Dim db As DAO.Database".

This code was provided to me and works beautifully in
another database. They are both Access 97. How can I fix
this?
 
T

Ted Allen

Hi Anne,

It sounds like your database is missing a reference to
the DAO Library. In the code window, go to
Tools|References on the menu and check to see if a DAO
library is referenced. If not, scroll down to find the
most recent version of Microsoft DAO available on your
list and check the box.

HTH

-Ted Allen
 
G

Gerald Stanley

In the VB Editor, go to Tools->References and put a check
against the entry for Microsoft DAO 3.6 Object Library

Hope This Helps
Gerald Stanley MCSD
 
E

Elwin

Open up the Visual Basic Editor to view your code. From
the menu, select Tools, References. Check off
the 'Microsoft DAO 3.6 Object Library'. Smooth sailing.
 
H

Heather

Check to see if your reference is set. In the code design
go to tools - Reference and see if Microsoft DAO 3.6
object Library is checked. I think 3.6 is for Access 97
but you can check the other db to make sure.
 
B

Bruce M. Thompson

Just a guess (and there's NO sarcasm on this one, because I don't have much
VBA experience), but is 'db' considered a reserved word? (of course, that
doesn't explain why it would work in another database...)

It's not a reserved word - it's an object variable name that is *very*
frequently used to represent a database object variable, so one might mistake it
for something built into Access.

:)
 
T

Ted Allen

Hi Mike,

DAO and ADO both contain Database objects in their
libraries. If you only have a reference to one or the
other, you can use dim db as Database and VB will
interpret it as a database object in whichever library
you have referenced.

But, if you reference both libraries, you need to
explicitly tell VB which library you are using, thus the
DAO preface in the original code. Actually, I believe
that if you don't preface the variable, VB will interpret
it as whichever type you give higher priority to, but it
is really best to explicitly specify for clarity anyway.

Many recommend that even if you currently only use DAO or
ADO, you consider explicitly dimensioning database and
recordset variables in case you ever have a need to add a
reference to the other.

HTH

-Ted Allen
 
C

Chris

Actually, ADO does not have a database object, but both
ADO and DAO have recordset objects.

By saying:
Dim rst as DAO.Recordset
Dim rst as ADODB.Recordset

makes your code faster too. Access does not have to look
through all the references to find the first Recordset
object.


Chris
 
T

Ted Allen

Thanks for the clarification Chris. I guess you can tell
that I mostly use DAO, but even with the limited amount
that I use ADO I should have remembered that. Glad you
caught it.

-Ted Allen
 

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