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

Open Database & Run Macro from Current Database 1

Status
Not open for further replies.

dbanker

Technical User
Sep 26, 2007
30
0
0
US
I am trying to write code that will open a database and run a macro from the database I currently have open. Here is the code I have written:

Dim db As DAO.Database
DoCmd.RunMacro "AppliQueryAll"
Set db = OpenDatabase("C:/2008 USDA/2008PSU/Arcview/ArcviewInfo.mdb")
DoCmd.RunMacro "AppliQueryPSU"
CloseCurrentDatabase
Set db = OpenDatabase("C:/2008 USDA/2008WRP/Arcview/ArcviewInfo.mdb")
DoCmd.RunMacro "AppliQueryWRP"
CloseCurrentDatabase
Quit

When I test the code I get the msg "Can't find macro AppliQueryPSU" which exists in the first database I am trying to open. I'm not sure but I think it is because it's being looked for in the original database instead of the one I'm opening. Any suggestions would be great. Thanks
 
Typed, untested:
Code:
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
DoCmd.RunMacro "AppliQueryAll"
WshShell.Run "msaccess ""C:/2008 USDA/2008PSU/Arcview/ArcviewInfo.mdb"" /x AppliQueryPSU", , True
WshShell.Run "msaccess ""C:/2008 USDA/2008WRP/Arcview/ArcviewInfo.mdb"" /x AppliQueryWRP", , True
Quit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top