Execute Procedure on a remote Access Db file

K

Kumar

I am trying to open another Access DB from my current Access DB and trying to
execute a SUB programatically. But I get a message that Microsoft Office
Access can't find macro "ParseMnAFileAGH" message. Any help on this is much
appriciated.

Here is my code:

SUB RunMacro()
dim objAccess as Access.Application
Set objAccess=CreateObject("Access.Application")
objAccess.OpenCurrentDatabase ("C:\MnAAH.mdb")
objAccess.docmd.RunMacro "ParseMnAFileAH"
objAccess.DoCmd.Minimize
Set objAccess = Nothing
End sub
 
D

Dirk Goldgar

Kumar said:
I am trying to open another Access DB from my current Access DB and trying
to
execute a SUB programatically. But I get a message that Microsoft Office
Access can't find macro "ParseMnAFileAGH" message. Any help on this is
much
appriciated.

Here is my code:

SUB RunMacro()
dim objAccess as Access.Application
Set objAccess=CreateObject("Access.Application")
objAccess.OpenCurrentDatabase ("C:\MnAAH.mdb")
objAccess.docmd.RunMacro "ParseMnAFileAH"
objAccess.DoCmd.Minimize
Set objAccess = Nothing
End sub


I don't think that is an exact quote of your code, which makes it harder to
debug for you. But if "ParseMnAFileAGH" or "ParseMnAFileAH" is the name of
a Sub, then RunMacro can't run it, because a VBA procedure is not a what
Access thinks of as a macro.

I'm not sure if you can call it directly, like this:

objAccess.ParseMnAFileAH

.... without setting a reference to the project. Feel free to try that and
report if it works. But if it doesn't, you can still probably call the
procedure by name, like this:

objAccess.Run "ParseMnAFileAH"
 
T

Tom van Stiphout

On Sun, 31 Jan 2010 15:21:01 -0800, Kumar

I think this code looks OK. One thing to check is the name of the
macro. In your message you're using both ParseMnAFileAGH and
ParseMnAFileAH.

-Tom.
Microsoft Access MVP
 
D

Daniel Pineault

Below is a bit of code to do as you ask that I came across a while back and
kept in case it could serve. Your problem is that you are using the
'.RunMacro' instead of the '.Run' command. As 'RunMacro' name states, it is
to run a Macro, not a VBA procedure.

Sub ForeignProcedure()

Dim appAccess As Access.Application

' Create instance of Access Application object.
Set appAccess = CreateObject("Access.Application")

' Open MyDatabaseName.mdb database in Microsoft Access window.
appAccess.OpenCurrentDatabase “C:\MyDatabaseName", False
'False so as not to open in exclusive mode
' Run Sub procedure.
appAccess.Run "ForeignProcedureName"
appAccess.Quit
Set appAccess = Nothing

MsgBox "Done!"

End Sub
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
T

Tom van Stiphout

On Sun, 31 Jan 2010 17:45:17 -0700, Tom van Stiphout

Ah, Dirk is right. Your code (once corrected for object name
misspellings) is to execute a macro.

-Tom.
Microsoft Access MVP
 
K

Kumar

Thanks Tom. The procedure name is correct. The type is in the message. Any
how. I double checked and the procedure name is "ParseMnAFileAH". Still havin
gthe same issue.
 
K

Kumar

Thanks for the tip Daniel. I changed the code per your suggestion.
Sub RunMacro()

Dim objAccess As Access.Application

Set objAccess = CreateObject("Access.Application")
objAccess.Visible = False
' Open AH Database
objAccess.OpenCurrentDatabase ("c:\MnAAH.mdb"), False
'Execute AH create Macro
objAccess.Run "ParseMnAFileAH"
objAccess.DoCmd.Minimize
Set objAccess = Nothing

End Sub

And here is the result.
Run-time error '2517':
Microsoft Office Access can't find the procedure 'ParseMnAFileAH.'

BTW: I am using Access 2003.
 
K

Kumar

Thanks for the suggestion Dirk. But that didn't work. Got compiler error
saying "Method or data member not found"
 
C

ChrisO

' Something to try.
'
' Just don't have the name of the Module
' in MnAAH.mdb the same as Sub ParseMnAFileAH
Sub RunMacro()

With CreateObject("Access.Application")
.OpenCurrentDatabase ("C:\MnAAH.mdb")
.Run "ParseMnAFileAH"
End With

End Sub
 
K

Kumar

It is defined as a sub under module (the procedure is too long to past here).

Thanks.
 
K

Kumar

Thanks ChrisO. I tried it with your suggestion with the same result. Any
other Ideas?
 
C

ChrisO

Are you sure the module name in the remote database is not the same as the
Sub name? I tested it with your names and it worked in A2003.
 
K

Kumar

Yes as a matter of fact they are the same (the module name and the SUB name),
is that an issue?
 
C

ChrisO

Only if you want it to work.

Try changing the Module name to something different.

Also while you are at it, did you declare the Sub as: -

Private Sub ParseMnAFileAH()

If so remove the word Private.
 
K

Kumar

ChrisO, you are a good man. I got is, when I changed my SUB name to something
other than the module name, it worked.
Keep up the good work my friend and thank you.
 
K

Kumar

Daniel, thank you. I found the problem. The My posted code is fine, but in my
remote database i named both the module and SUB name same . WHen I changed
the SUB name it worked like a chard. Thank you for your help for getting me
to that point. Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top