OpenDatabase errors

  • Thread starter Thread starter MeSteve
  • Start date Start date
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?
 
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.
 
Back
Top