Command button to open another database?

G

GD

I have a command button on a form that opens another form within the same
database. Is it possible to have one that opens a separate database? Right
now my code for the former is:

Private Sub GoToCMLabels_Click()
DoCmd.OpenForm "frmCMLabelsDataEntry", acNormal, "", "", , acNormal
DoCmd.Close acForm, "frmCMDMSearch"

End Sub

If possible, what would the code look like to open a separate DB?
 
E

Ed Robichaud

Access can only have one database open at a time, though you can be linked
simultaneously to many data files. You can however program a command button
to open another instance of Access to show your other database.

You can use the command button wizard to generate code similar to below:

Private Sub btnOtherDB_Click()
On Error GoTo Err_btnOtherDB_Click

Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\Office10\MSACCESS.EXE
FullPathName\MyApp.mdb"
Call Shell(stAppName, 1)

Exit_btnOtherDB_Click:
Exit Sub

Err_btnOtherDB_Click:
MsgBox Err.Description
Resume Exit_btnOtherDB_Click
End Sub


-Ed
 
K

Kevbro7189

2007 Can have two DB open at once, I’m not sure about the others. The
easiest way I have found to do this with a button is to use a Macro with the
ACTION (RunApp) and the COMAND LINE something like ("C:\Program
Files\Microsoft Office\OFFICE12\Access.EXE" "C:\File\AccessFileName.mdb")

The file locations will change.
Make sure you use the quotes.

Hope this helps
Kevbro
 
G

GD

Hey Ed. Your solution works great, but I'm running into a problem because
one of the subfolders I have to use to get to the new DB has a space in it.
Is there a way to alter the code to account for that? I don't have the
option of changing the folder name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top