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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command button on form opens form in another DB 1

Status
Not open for further replies.

NewTexican

Technical User
Dec 10, 2004
95
US
Can someone lead me to some example code that will let me open a form in one database with a command button from another database?
 
I don't know if there's a more elegant way, but this will work. Create an macro in the db you want to call with a macro containing an Openform action for the form you want to open. Then Create a macro (say, mOpenForm) in the calling db containing the action:
RunApp "C:\Program Files\Microsoft Office\Office10\Msaccess.exe" "c:\temp\db.mdb" /x macro1

Here c:\temp\db.mdb is the db containing the form you want to open and macro1 is the macro containing the OpenForm

Now just attach DoCmd.RunMacro "mOpenForm" to a button in the calling form

If you always want the same form opened in the second db, call that macro autoexec and the you can leave out /x macro1

Simon Rouse
 
Ok this works good unless the form is already open, then I get a new database with a second instance of the same form. Normally I would just put an if then statement with isloaded, but the command button that runs the calling macro is on the switchboard. I cracked open the switchboard code and it is above my head. Is there a way to put an if then statement in the macro itself? Can you give me any guidance on the switchboard code?
 
Sorry - have only rarely used the switchboard can't help there.
I'm not aware that you can use If within macros. You could do that outside the macro environment:
If Test then
DoCmd.RunMacro "mMacro1"
Else
DoCmd.RunMacro "mMacro2"
End If


 
Thanks. I just made my own switchboard because I'm sure I'll have to add other code as well. I've never used macros except autoexec for the switchboard so thanks for the info.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top