Open a 2nd Database and close current (1 Viewer)

JReagan

Registered User.
Local time
Today, 15:30
Joined
Oct 13, 2009
Messages
32
I have some code here that works fine as far as opening up a second database. The problem I seem to be running into now is when I close the original Db, the new database I just opened closes too.
Any ideas out there on how I might add some code to this? My goal is to have this code in a form and when ran from the Current Db, it would open a 2nd database then close the current.

*****Begin Code*****
Option Compare Database

Public Function OpenDB()
Dim DB
Dim strDbName
Dim strPassword
strDbName = "c:\File_Path"
strPassword = "MyPassword"
Static acc As Access.Application
Set acc = CreateObject("Access.Application")
acc.Visible = True
Set DB = acc.DBEngine.OpenDatabase(strDbName, False, False, ";PWD=" & strPassword)
acc.OpenCurrentDatabase strDbName

End Function

*****End Code*****

JB
 

boblarson

Smeghead
Local time
Today, 15:30
Joined
Jan 12, 2001
Messages
32,059
The thing to remember here is that when you open the other database you are doing so within the original so if the original closes, the second one closes UNLESS you add this to the end of your code:

Code:
acc.UserControl = True
 

JReagan

Registered User.
Local time
Today, 15:30
Joined
Oct 13, 2009
Messages
32
I can't seem to get "DoCmd Quit" to work at the end, or "acc.CloseCurrentDb". Any thoughts on this?

JB
 

boblarson

Smeghead
Local time
Today, 15:30
Joined
Jan 12, 2001
Messages
32,059
You don't want to use acc.CloseCurrentDb as that refers to the second one. So, what do you have now for the code?
 

JReagan

Registered User.
Local time
Today, 15:30
Joined
Oct 13, 2009
Messages
32
Bob: Actually I resolved this last night. With the Macro that I'm using to run the code, I just added another line to it with the command "Quit". Everything seems to be working great now!

Thank you again for your speedy response and help with this.

JB
 

Users who are viewing this thread

Top Bottom