Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch databases with VBA? 1

Status
Not open for further replies.

snoopy75

Technical User
Aug 24, 2001
340
0
0
US
I'm trying to find a way to physically switch active databases during run-time. Here's the code I have so far:

Public Sub OpenNewDB()

Const strPath = "C:\Devices.mdb"

Application.CloseCurrentDatabase
Application.OpenCurrentDatabase strPath

End Sub

This code will close the current database just fine, but it doesn't open the other database. I suppose that closing the current database also terminates the running code. Is there any way around this?
 
Here's how I do it. (Access 97)

stAppName = "MSAccess.exe " & CurrentDb.Name
Call Shell(stAppName, 1)
DoCmd.Quit

You can change CurrentDb.Name to be any database path and name. Maq B-)
<insert witty signature here>
 
Nice! That works great!

Now, for extra credit ;-), is there any way I can do it without having to re-input my username and password?
 
Ouch! Well, I've never used Access's built in security so I don't know how it works. Perhaps a command line option in the shell statement? Maq B-)
<insert witty signature here>
 
To have programmatic control over the newly opened database, use automation to open it which will return an application reference you can use to control things. The security is contained in the workspace object so you'd need to create a new work space or clone the default workspace.

Luther
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top