Is it possible to be in a database (I will call it dbAlpha) and run a macro from another database (dbBravo, macro is called Charlie)?
Can this be done from the macro line or is it some type of code.
Please help. steve69
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Run macro from a separate DB??
You can’t “attach” a macro. And you won’t be able to call one in another database except from code. The big question is why you would want to do this at all. Access macros are no substitute for code, lack error handling, and complex macros are at least as difficult to write as simple code would be.
The two databases track different items, one for operator productivity and the other tracks operator errors and corrective actions.
Month End Reports get ran out of both dbs. In the past I would run all the reports and break them down for distribution. However, I am now trying to automate the printing of the reports for one of my assistants.
I was looking for a way to run all the reports at once without having to open each database.
steve69
Hi. This subject interests me too. I have three databases which run reports automatically at night. I have built a forth database which backs up and compacts the other three, but of course, this can’t be done if the databases are open. What i have mananaged to do is run macros within the three from the forth using run msaccess.exe /db name etc (actual code on request), but i am sure it must be possible to run code remotely by creating a workspace??? I agree, running macros is not at all nice compared to running code, which is why i would love to get this sorted out.
At the moment i have to leave all four open, and then rely on a whole bunch of timers to run reports and close each app. down before the timer on the compactor kicks in, but i really would like to be able to “control” each of the three from the fouth.
At the risk of inviting Charlotte’s wrath….
Here’s a code example you can use:
Function RunExternalReport() Dim AccessApp As New Access.Application Dim strDB As String strDB = "C:Program FilesMicrosoft OfficeOfficeSamplesNorthwind.mdb" AccessApp.OpenCurrentDatabase strDB AccessApp.DoCmd.OpenReport "Report1", acViewNormal AccessApp.CloseCurrentDatabase Set AccessApp = Nothing End Function
Of course, you’ll want to add error handling but this is the general idea. After the OpenCurrentDatabase command, you can use the DoCmd object (or any other object for that matter) of the external database to do anything you need.
HTH
I also have a date field in the second database that I would like to link prior to running this code (which works very well, thanks). Can I add a line to the code like?
set [table1].[startdate] = [table2].[startdate]
Do I need to specify the db name in the equation? How do I specify a db name that contains spaces?
sorry for the multiple questions.
steve69
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.