0

I am using currentDb method to get instance of database in VBA excel macro. I have added reference as well but CurrentDb method is giving error "Variable Not Defined"

Below is code

Dim Db As DAO.Database

Db = CurrentDb

Could you please help me on this

2
  • Added reference DAO 3.6 object library Commented Sep 11, 2018 at 5:22
  • CurrentDb is an Access method, so it's not going to work by itself in Excel VBA. Maybe if you posted more code someone might have a suggestion. With only two lines not much to go on. Commented Sep 11, 2018 at 6:19

1 Answer 1

4

CurrentDb is an Access-specific global variable which is not defined in Excel.

You need to open a database instead:

Dim Db As DAO.Database
Set Db = OpenDatabase("C:\Users\Fred\Databases\Foo.mdb")

OpenDatabase is a member of the global object DBEngine from the Microsoft DAO 3.6 Object Library (which I assume you have referenced because your code has the DAO.Database type).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.