Error Message "User-defined type not defined"

  • Thread starter Thread starter Anne
  • Start date Start date
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?
 
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
 
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
 
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.
 
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.
 
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.

:-)
 
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
 
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
 
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
 
Back
Top