OpenCurrentDatabase in Second Instance of Access Does Not Throw Error If It Failes

S

Stewart Berman

Access 2007

I have code that creates a second instance of Access and uses it to open another database as its
CurrentDB:
Set mappAccess = New Access.Application
mappAccess.OpenCurrentDatabase strPathDBName, False, strPassword

If the OpenCurrenDatabase method fails (i.e. the strMDBPath is locked because it is already opened
in exclusive mode) it does not throw an error. It just doesn't open the database.

If I open Access and manually try to open a database that is locked Access throws an error saying it
can't open it.

Why doesn't the OpenCurrentDatabase method throw an error? Is this by design?
 
T

Tom van Stiphout

On Mon, 12 Oct 2009 18:51:55 -0400, Stewart Berman

I tested this in A2010, added a line:
mappAccess.Visible = True
and kept a close eye on the Task Manager.
It did open my second db, even though I had already opened it
exclusively. Perhaps A2007 has the same behavior.

-Tom.
Microsoft Access MVP
 
S

Stewart Berman

The second instance of Access was visible in my tests and not minimized. I could see Access
opening. It did not open the data base and did not throw an error.

In fact if I use the second instance of Access and manually try and open the same database it does
nothing.

I then did the following. I opened an new instance of Access using the Access 2007 shortcut and
then opened a database (db2.accdb) in exclusive mode. Then I used the "automated" instance of
Access and tried and to open the db2.accdb and nothing happened -- no error -- just the Getting
Started with Microsoft Office screen. I could use the "automated" instance to open another database
that was not locked.

So there is something strange about the instance that was opened via
Set mappAccess = New Access.Application
The only way to know that:
mappAccess.OpenCurrentDatabase strPathDBName, False, strPassword
fails is to check to see if mappAccess.CurrentDB is Nothing.

Finally, I did one more thing. I changed the code to:
Set mappAccess = New Access.Application
mappAccess.OpenCurrentDatabase strPathDBName, False, strPassword
set mappAccess = nothing

The database still was not open but now when I tried to open it using the instance of access created
above it threw an error saying it could use the file because it was already in use.

It would appear that while mappAccess still had a valid pointer to the Access application the
application would not throw an error. Once the pointer was released and the Access application was
on its own it did throw an error.

I am supprised that 2010 let you open an database in a seperate instance of Access that was already
open in exclusive mode. You said you kept a close eye on the Task Manager. Why? The "automated"
instance of Access should be visible on the desktop unless you minimized it. You should see the
Navigation Bar for the database it opened. Did it actually open the database or did you just see an
instance of Access in Task Manager and on the Taskbar?
 
S

Stewart Berman

I appreciate your comments but they do not appear to have anything to do with the problem I
described -- which is the failure of a second instance of Access to throw an error when it cannot
open a database.

Maybe I missed something -- please explain how your comments would help me trap the error.
 
S

Stewart Berman

I don't think you read the thread.

The problem is that I have a front end database running VBA code. It has links to a back end
database. Both are .accdb files.

The front end code instantiates another instance of an Access application. That instance then tries
to open the back end database in exclusive mode and fails -- which is expected since the back end
already has connections. The problem is OpenCurrentDatabase method does not throw an error when it
fails.

The question is why isn't an error thrown?
 
S

Stewart Berman

Unfortunately, this is not a "managed" newsgroup and as such is not actively monitored by MS
personnel. I didn't realize this until a few days ago. I have found a number of bugs in Access
2007 that I have posted here. When I have time I will copy the postings to a "managed" newsgroup.
 

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