From one Access 2007 database, I'm using automation to open another Access 2007 database. I want the first database to close after the 2nd one opens. I cannot use followhyperlink or Shell command to open the 2nd database because it is password protected. Because it's automation, I cannot drop the app or set it as nothing or the 2nd instance will close out. So, meanwhile, when I try to close the 1st database and use the cmd "QUIT", it closes BOTH databases or only the 2nd database, which isn't what I need. HELP! I'm pulling my hair out since Access 2007 came out....Simple things have changed.
See code below:
------------------------------------------
Function GetDB()
Dim DBPWD1 As String
On Error Resume Next
DoCmd.Hourglass True
DBPWD1 = "12345"
Dim dbs As Database
Dim dbs2 As Database
dbpath = "C:\RBHS\RBHS.mde"
Static Acc As Access.Application
strdbname = dbpath
Set Acc = New Access.Application
Acc.Visible = True
Set dbs = Acc.DBEngine.OpenDatabase(strdbname, False, False, ";PWD=" & DBPWD1 & "")
Acc.OpenCurrentDatabase strdbname
Acc.RunCommand acCmdAppMaximize
'THE ITEMS BELOW ARE COMMENTED OUT BECAUSE THEY CAUSE THE
'2nd DB TO CLOSE
'dbs.close
'Set dbs = Nothing
'Acc.Quit
'Set Acc = Nothing
'THE BELOW DOES NOT WORK BECAUSE IT CLOSES ALL INSTANCES,
'BOTH DATABASE 1 AND DATABASE 2
strdb = "DatabaseOne"
Set AppAccess = GetObject(strDB, "Access.Application")
AppAccess.Quit
'BELOW DOENS'T WORK EITHER
DoCmd.quit
End Function
---------------------------------------
See code below:
------------------------------------------
Function GetDB()
Dim DBPWD1 As String
On Error Resume Next
DoCmd.Hourglass True
DBPWD1 = "12345"
Dim dbs As Database
Dim dbs2 As Database
dbpath = "C:\RBHS\RBHS.mde"
Static Acc As Access.Application
strdbname = dbpath
Set Acc = New Access.Application
Acc.Visible = True
Set dbs = Acc.DBEngine.OpenDatabase(strdbname, False, False, ";PWD=" & DBPWD1 & "")
Acc.OpenCurrentDatabase strdbname
Acc.RunCommand acCmdAppMaximize
'THE ITEMS BELOW ARE COMMENTED OUT BECAUSE THEY CAUSE THE
'2nd DB TO CLOSE
'dbs.close
'Set dbs = Nothing
'Acc.Quit
'Set Acc = Nothing
'THE BELOW DOES NOT WORK BECAUSE IT CLOSES ALL INSTANCES,
'BOTH DATABASE 1 AND DATABASE 2
strdb = "DatabaseOne"
Set AppAccess = GetObject(strDB, "Access.Application")
AppAccess.Quit
'BELOW DOENS'T WORK EITHER
DoCmd.quit
End Function
---------------------------------------