Hello friends,
I want to open a Access database (aka Db1), run a macro, then close the database from a separate database (aka Db2). The code below works great to open Db1 and run the macro from Db2. But Db1 stays open. I attempted to add QuitAccess to the end of the macro. When I ran the code from Db2, I got a Microsoft Visual Basic error "Run-time error 2501. The RunMacro action was cancelled" and the objAccess.DoCmd.RunMacro "MACRO NAME" part of the code was highlighted. How can I get Db1 to close after the macro completes? Thanks in advance for your suggestions.
Cheers, Kevin
Public Function RunSeparateDbMacro()
Dim objAccess As Access.Application
Set objAccess = CreateObject("Access.Application")
objAccess.Visible = True
'Open Test.mdb exclusively
objAccess.OpenCurrentDatabase "C:\DIFFERENT DATABASE PATH\DIFFERENT DATABASE NAME.accdb", True
objAccess.DoCmd.RunMacro "MACRO NAME"
objAccess.DoCmd.Maximize
Set objAccess = Nothing
End Function