Dim dbs as Database

IfButOnly

Registered User.
Local time
Today, 14:29
Joined
Sep 3, 2002
Messages
236
whenever I go to run a piece of code from HELP, sample code etc., which contains the statement:

Dim dbs as Database

it returns the error
-----------------------------------------
Compile Error:
User-defined type not defined
-----------------------------------------

as I haven't had the need to use this (except to learn more), I usually fiddle around for an hour or so, and then give up.

Can anyone tell me what the problem is? Obviously there is a chunk of knowledge that I am missing out on for this style of coding - can you point me to a good source?

Thanks in advance ............... PeteR.
 
Check your VBA references...

...you may need to add a reference to DAO
 
You need to add (I can't remeber which)

Set dbs = Currentdb()

or just

dbs = Currentdb()

as long as it's the db your using that you want to connect to.....
 
In the VB window go to Tools>References

Make sure that you reference to Microsoft DAO 3.6 is higher priority than Microsoft ActiveX Data Objects 2.5
 
or define it explicitly for added safety

Dim dbs as dao.database
set dbs = CurrentDb
 
WHy is it that the DAO library functions must be accompanied by DAO.whatever?
It took me a week, and not to mention having the SysAdmin come down stairs and make me look like a blundering idiot, to figure this out.
Why can't it just be:
Dim myVar As Recordset

Instead of:

Dim myVar As DAO.Recordset

Frustrating
 
With A2K, Access uses ADO as the default data access library. If you want to continue to use DAO, you need a reference to the DAO library and unless you remove the reference to the ADO library or move it down the list so that it follows the DAO reference, you will need to qualify your DAO object names.
 
Thanks guys, I set up the DAO reference as suggested and that got me past the problem.

I noticed I had only the following items checked in the reference list:-
.. Microsoft Access 9.0 Object Library
.. OLE Automation
.. Microsoft ActiveX Data Objects 2.1 library

are there other items I should add?

Thanks again .... PeteR.
 
This is the standard set of refs. Unless you plan to use ADO, you can safely deselect Microsoft ActiveX Data Objects 2.1 library.
I have done this and left in the DAO 3.xx as a couple of times, when copying the Db to another computer, it places ADO above DAO on the list regardless.
You only need to add libraries if you call 'their' code from MS access. For example, I often call MSword from access, passing commands to it and if I do not include the Microsoft Word library, access throws up compile errors (and rightly so!).

hope this is helpful.
 

Users who are viewing this thread

Back
Top Bottom