VBA: How do I know if the database is opened?

G

Gustaf

I'm opening a database using the following code:

Dim accApp As Access.Application

' Load Access file
Set accApp = New Access.Application
accApp.Visible = False
accApp.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityLow
accApp.OpenCurrentDatabase sAccessFile, True

Unfortunately, this results in a security warning the user must deal with manually. If the user clicks Cancel there, execution will continue as usual with no database open, until it crashes. So after OpenCurrentDatabase, I need to check whether the database is really open. How can I do that?

Gustaf
 
P

Paul Shapiro

I didn't test it, but you could either check the value of
(accApp.CurrentProject Is Nothing) or trap the error in an error handler. I
would look into eliminating the security warning as a potential better
solution.
 

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