Tags: access, anoth, application, cant, code, current, database, error, exclusively, microsoft, missing, mysql, objectthrough, oracle, sql

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

On Database » Microsoft Access

5,428 words with 2 Comments; publish: Fri, 06 Jun 2008 11:38:00 GMT; (2501,699.22, « »)

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

All Comments

Leave a comment...

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

      Do a Google search of PrivDBEngine for more details.

      Doug Steele, Microsoft Access MVP

      http://I.Am/DougSteele

      (no e-mails, please!)

      "David McDivitt" <x12code-del.ms-access.questionfor.info.del-yahoo.com> wrote in message

      news:rkbjb1hpodnc044kot3inr8ff31o35ca69.ms-access.questionfor.info.4ax.com...

      >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

      >

      #1; Fri, 06 Jun 2008 11:39:00 GMT
    • >Subject: Re: error 7866, can't open the database because it is missing, or opened exclusively by another user[vbcol=seagreen]

      >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.

      >--

      >Doug Steele, Microsoft Access MVP

      >http://I.Am/DougSteele

      >(no e-mails, please!)

      >

      >"David McDivitt" <x12code-del.ms-access.questionfor.info.del-yahoo.com> wrote in message

      >news:rkbjb1hpodnc044kot3inr8ff31o35ca69.ms-access.questionfor.info.4ax.com.. .

      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...b;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.

      #2; Fri, 06 Jun 2008 11:40:00 GMT