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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)


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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

764 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