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!

Dim Db as database 1

Status
Not open for further replies.
Jul 18, 2002
46
US
Why do I get the message "Compiler Error: User-defined type not defined" when I try to dim a database.

Laura
 
Check the references you have set. There should be a reference to one of the DAO libraries.
 
I'm sorry this is the first time I've tried using DAO and I have no idea what you're talking about. How do I check this ?
 
When you're in the VBA code window, use the menu "Extra" and there click on "References". You'll get a screen with a litbox. Microsoft DAO 3.5 (or whatever version) Object Library should be checked...

Niki
 
Appearantly in the English version, the menu is called "Tools". Sorry bout that :)
 
Thanks, That works but now I get a type mismatch error when I try to run this code (or any code for that matter). Can anyone tell me what's causing that? I bolded the line that gives the error.

Dim dbs As Database, tdf As TableDef, fld As Field

' Return Database object variable pointing to current database.
Set dbs = CurrentDb
' Return TableDef object variable pointing to TankInventory table.
Set tdf = dbs.TableDefs!TankInventory
' Enumerate fields in TankInventory table.
For Each fld In tdf.Fields
Debug.Print fld.Name
Next fld

Thanks,
Laura
 
You probably have a reference checked to the ADO library. ADO and DAO have some of the same objects, so it is necessary to explicitly define if both libraries are available.

Dim dbs As DAO.Database, tdf As DAO.TableDef, fld As DAO.Field
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top