error 7866, can't open the database because it is missing, or opened exclusively by another user

D

David McDivitt

I am trying to set the current database for the access application object
through code and keep getting the error 7866: Microsoft Access can't open
the database because it is missing, or opened exclusively by another user.

At the start of the code I do the following:
dao.DBEngine.SystemDB =
dao.DBEngine.DefaultUser =
dao.DBEngine.DefaultPassword =
With this I can successfully use the DAO opendatabase method and do stuff.
At another phase I need to create an application object and set the current
database for that object. Open creating the application object the first
thing I do is:
TempApp.DBEngine.SystemDB =
TempApp.DBEngine.DefaultUser =
TempApp.DBEngine.DefaultPassword =

Following this, when I do the opencurrentdatabase method I get the 7866
error. The problem is probably because dbengine is already initialized,
though I have not yet done anything with the application object. Setting the
dbengine values only works before it is initialized. To fix, the values must
be put in an ini file or in the registry, and those values read by
MSAccess.exe when it creates the application object. Can someone tell me how
to do that? Thanks
 
D

Douglas J. Steele

I believe you need to use PrivDBEngine, rather than DBEngine.

Do a Google search of PrivDBEngine for more details.
 
D

David McDivitt

Subject: Re: error 7866, can't open the database because it is missing, or opened exclusively by another user
Date: Wed, 22 Jun 2005 17:20:51 -0400

I believe you need to use PrivDBEngine, rather than DBEngine.

Do a Google search of PrivDBEngine for more details.

Thanks Doug. I will use that when needed from within MSAccess with VBA. It
still does solve the problem with the application object. I found a
Microsoft article saying how to do this:
http://support.microsoft.com/default.aspx?scid=kb;en-us;192919
How To Automate a Secured Access Database Using Visual Basic

I have used the VB createobject function many times, but never used the
getobject function. Code follows:

dao.DBEngine.SystemDB = "wherever"
dao.DBEngine.DefaultUser = "whoever"
dao.DBEngine.DefaultPassword = "whatever"
FileCopy AnalPath & "\" & AnalFile, TempFile
Set TempDB = OpenDatabase(TempFile)
TempDB.Properties.Delete "AllowBypassKey"
'harvest the document names because accessing them fails when done through
application object
For Each doc In TempDB.Containers("Forms").Documents
For Each doc In TempDB.Containers("Reports").Documents
For Each doc In TempDB.Containers("Modules").Documents
For Each tdf In TempDB.TableDefs
For Each qdf In TempDB.QueryDefs
TempDB.Close
Set TempDB = Nothing
a = RegFunGetValue(HKEY_CLASSES_ROOT,
"Access.Application.9\shell\open\command", "", "")
If Left(a, 1) = Chr(34) _
Then
a = Mid(a, 2)
p = InStr(a, Chr(34))
Else
p = InStr(a, " ")
End If
If p = 0 Then p = Len(a) + 1
a = Trim(Left(a, p - 1))
keybd_event VK_SHIFT, 0, 0, 0
Shell """" & a & """ /NOSTARTUP /USER ""whoever"" /PWD ""whatever"" /WRKGRP
""wherever""", vbHide
Set TempApp = GetObject(, "Access.Application.9")
TempApp.OpenCurrentDatabase TempFile

Since I got this working, an open form call fails on occasion. Have to see
why. Other than that works real good.
 

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