opening external database form problem

dpotts

Registered User.
Local time
Yesterday, 18:29
Joined
Jul 3, 2008
Messages
10
I am trying to open a database form from another database and this is the code I have to do that.

Dim appAccess As Access.Application
Dim strDB As String

strDB = "C:\Documents and Settings\dave\Desktop\Music Library.accdb"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strDB
appAccess.Visible = True
appAccess.DoCmd.OpenForm "frmMain"

It works fine for the first second. I can see the database open and the form will be displayed, but less than a second later the database just closes. Is there some kind of code that I need to put in there to keep the database open?
 
Maybe your appAccess object goes out of scope. Declare the object outside of the procedure that creates the object and opens the form...

Code:
dim appAccess as access.application

public sub OpenForm
  Dim strDB As String

  strDB = "C:\Documents and Settings\dave\Desktop\Music Library.accdb"
  Set appAccess = CreateObject("Access.Application")
  appAccess.OpenCurrentDatabase strDB
  appAccess.Visible = True
  appAccess.DoCmd.OpenForm "frmMain"
end sub
...otherwise your object reference is destroyed when the subroutine ends.
 
Yes, that worked. Thanks.

But now another issue comes up. This second database is closed when I close the first one. Now I know that the database object is gone when the first database is closed. Is there any way to make the object stay? Or any way to make it a permanent object?
 
I don't understand your questions. If both databases are closed then you have two permanent files on disk, but you have no running code so you have no instance of an "object." The concept "object" has no meaning when code is not running.
Do you mean you want to launch the second database from the first? Close the first and leave the second running? You can do that.
 
Do you mean you want to launch the second database from the first? Close the first and leave the second running? You can do that.


Exactly. I suppose I should have asked the question in its simplest form. Now how would I go about doing this?
 
Check out the Shell() function, which runs an executable program.
Cheers,
 

Users who are viewing this thread

Back
Top Bottom