running Access procedure from Excel

S

savalou

Hello,

I'm trying to run a procedure in access using excel VBA. I set the
access object library reference and ran this code but it hangs on the
appAcc.run command; Run-time error '440': Method 'Run' of object
'_Application' failed.


Sub GetKenyaAPRdata()
Dim appAcc As Access.Application
Set appAcc = New Access.Application
appAcc.Visible = False
appAcc.OpenCurrentDatabase ("C:\PMS\PEPFARresults.mdb")
appAcc.Run "getdata_Kenya"
appAcc.Quit
Set appAcc = Nothing
End Sub

Thanks in advance!

Dave
 
J

JW

is "getdata_Kenya" the name of a query in your database? A module
name? A sub procedure name? If it's a query, you could use:
appAcc.DoCmd.OpenQuery "getdata_Kenya"

If a function, try this:
appAcc.DoCmd.OpenFunction "getdata_Kenya"
 
S

savalou

is "getdata_Kenya" the name of a query in your database? A module
name? A sub procedure name? If it's a query, you could use:
appAcc.DoCmd.OpenQuery "getdata_Kenya"

If a function, try this:
appAcc.DoCmd.OpenFunction "getdata_Kenya"








- Show quoted text -

It's a sub procedure.

Thanks,

Dave
 
G

Guest

Works for me. Could this be a security issue where you need to enable macros
to be run? In Access 2003 I specifically have to click "Open" in a dialog
because it has code in it.
 
S

savalou

Works for me. Could this be a security issue where you need to enable macros
to be run? In Access 2003 I specifically have to click "Open" in a dialog
because it has code in it.










- Show quoted text -

I have the macros enabled. This is working for me now. I was getting
an error message, but it was actually peforming the sub routine, so I
put an 'On error resume next' before the appAcc.Run "getdata_Kenya" .
Still don't know what the error is all about.

thanks again for your time.

Dave
 
G

Guest

Looks like there's something in "getdata_Kenya" that's erroring out.
Possibly the error doesn't happen when you run it from Access, but just from
Excel?
 

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