Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Dim CurrentDB not compiling correctly

Posted on 2003-03-09
Medium Priority
Last Modified: 2006-11-17
I am working with MSAccess VBA in a public sub in a module, but the autocomplete function does not show "Database" when I type "Dim db as " in the declarations section.  I understand it is normal to write something like this:
Dim db As Database
set db = CurrentDb()
With db... etc.etc.
but my compiler is not recognizing this.
I have used the above statements in Access 97.  Is there a change to Access 2000?
Is my database somehow not lined up for these statements?  Have I missed a crucial statement or setting in Access 2000?
Question by:stcjapan

Accepted Solution

graham_charles earned 375 total points
ID: 8101062
There's no change, but you may not have included the Microsoft Data Access Objects library in your project; that's the library that includes the Database type.

From the code window, choose Tools / References and make sure the latest version of Microsoft Data Access Objects is included in your project.


Expert Comment

ID: 8101097
Microsoft was moving away from DAO with Access 2000, so removed the DAO objects included by default in the previous versions, from the default references in this and future versions. You do have access to the objects via methods (like CurrentDb), but the library is hidden without an explicit reference.

graham_charles' comment is on target on how to create the reference, but without it, you can still:

Dim db as Object

Set db = CurrentDb

to return a reference to the current database as a DAO object.

Expert Comment

ID: 8101397
1) You must reference the DAO library
In the Visual Basic Editor on the Tools menu, click References and find the "Microsoft DAO 3.51 Object Library". Select it.

2) If you want to benefit from intellisense when typing your code, you must prefix the class in the Dim statement:

Dim db as DAO.Database
Dim rst as DAO.Recordset

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 8101718
If you reference DAO, be sure it's above the standard reference to ADO in the list (higher priority) or you might still get errors. gnicoli's suggestions of prefixing with DAO. will prevent those errors though. You can probably remove the ADO reference since you're using DAO anyways.

Expert Comment

ID: 8104074
Again, doesn't hurt to reference DAO, but you don't _need_ to; the objects are available, just hidden.

Author Comment

ID: 8133233
Many thanks, that fixed things quick

Expert Comment

ID: 8136020
mcallarse, and what if I want to dim a recordset of type DAO? Then you'll need to reference DAO. Otherwise Dim MyRS As DAO.Recordset won't work.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question