I'm very self-taught at VBA and have hit a snag that I cannot solve. I have an Access 2010 database from which I need to click a command button that will open another existing database, run a macro in that database, and then close it so I am just left with my original database open. Here's what I have so far...
Code:
Public Sub Command109_Click()
Dim accapp As New Access.Application
With accapp
.OpenCurrentDatabase ("C:\HR\Staging 2.accdb"), False
.Visible = True
.DoCmd.RunMacro "Import File"
End With
End Sub
I've reached this after tons of permutations of code borrowed from 2003 databases that accomplish a similar task and random bits and pieces I've found around the internet. As of right now, when I click the button the other database opens, and I know that macro begins to run because I get a pop-up box that is part of the macro, but then before the macro completes (all it is doing is importing a text file to the 2nd database...) I get run-time error 2501 that my macro action has been cancelled and I can't figure out why.
Could someone please help me get this code to the point where it either opens the database, runs the macro, and closes the database, or I think I would also be comfortable setting it up to open the database and to have the macro up to autoexec if I can make the sub close the database when the autoexec macro is complete. Any help would be sincerely appreciated!