views:

157

answers:

1

From Excel, I need to open an Access database and run one of the database's macros.

I'm using Excel and Access 2007. Here is my code in Excel:

Sub accessMacro()

   Dim appAccess As New Access.Application

   Set appAccess = Access.Application

   appAccess.OpenCurrentDatabase "C:\blah.mdb"

   appAccess.Visible = True

   appAccess.DoCmd.RunMacro "RunQueries.RunQueries"
   appAccess.CloseCurrentDatabase

End Sub

In the Access Database, there is a procedure named RunQueries in a module named RunQueries. Each time I run this, I get the following error:

Runtime error '2485':

Microsoft Access Office can't find the object 'RunQueries.'

I have also tried:

appAccess.DoCmd.RunMacro "RunQueries" 

and I get the same errors message. Any idea how to do this? By the way, I could go into a long explanation about why I need to do this, but let me just say that I've already argued against it, and I have to do it this way (meaning, I have to use Excel as a frontend to open several Access dbs and run their macros).

+1  A: 

What about this syntax ?
appAccess.run "RunQueries.RunQueries"

By the way, I always avoid naming a module like a procedure. This is looking for trouble.

iDevlop
I tried this, and it did not work. I then tried changing the name of the module so that it was different from the procedure name, and it still did not work. The error is: Run-time error: '2517'Microsoft Office Access can't find the procedure 'RunQueries.'
oob
That error msg is a progress...I tested the syntax I gave you. It should replace the ...runmacro line in you example.Is you procedure public ? Don't you have an Option Private at module level ?
iDevlop
oh, and Set appAccess = Access.Applicationis not necessary unless you remove the "New" in the line above.
iDevlop