OpenDatabase errors

M

MeSteve

I am programming a powerpoint to retrieve data from a database. I am using:

Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase("\\Folder Path\ProjectTracker_be.accdb")
Set rs = db.OpenRecordset("tbl_Projects")

At first, I was getting an error that the database was not open. Opening
the database before I ran my code seemed to fix this. This does not seem to
be a reliable enough solution for a production product as I sometimes still
get the error that the databse is not open.

Is there a more reliable way to access my data, maybe without using
OpenDatabase and having to have the database open at all?
 
K

Klatuu

First, be sure you have a VBA reference to Microsoft DAO 3.6 Object Library.
Then specify your Dim Statements to be DAO objects:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Then to be extra sure it is using the correct object model add the qualifier
to your code:

Set db = DAO.OpenDatabase("\\Folder Path\ProjectTracker_be.accdb")
Set rs = db.OpenRecordset("tbl_Projects")

That should cure the problem.
 

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