Set mydb as database

L

Lost

Hi
Don't laugh ... but I'm completely lost in this Access VBA
code.

When it says to

set mydb as database

Do you actually put mydb or do you type in your database
name??? eg: I called mine db1 so would i type in...

set db1 as database
???
HELP!
 
V

Van T. Dinh

"mydb" is simply an Object Variable name and it doesn't have to be the name
of your Database. Also the correct syntax is:

Dim mydb As Database

and you instantiate the Object Variable later with:

Set mydb = CurrentDb()

or some other method.

You need to include the DAO Object Library in the References Collection of
your database.

If you not familiar with VBA, suggest you read through an introductory
Access VBA book to get a good understanding of the basic concepts in VBA as
well as the oft-used constructs.
 
A

Allen Browne

Yes: use whatever name suits you, such as:
Dim SomeName As Database
Set SomeName = CurrentDb()

Notes:
1. The Dim line declares you want a variable of type Database.

2. The Set line points that variable to the current database.

3. If this code fails, choose References on the Tools menu, and check the
box beside:
Microsoft DAO 3.6 Library
The Database object is part of that library.
More info on references:
http://allenbrowne.com/ser-38.html

4. At the end of your code set this and all other objects to Nothing:
Set MyDb2 = Nothing
(Anything you assigned with "Set" is an object.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top