Running an Access Procedure from excel. Procedure takes parameters.

ChrisOswald

Active Member
Joined
Jan 19, 2010
Messages
454
Hi,

I think this just a syntax question, but I couldn't figure it out via trial and error.

In excel, I'm attempting to run a sub in an Access .mdb. The access .mdb is declared as follows:

Code:
Sub DiscReportingMain(DistNbrStr As String, PeriodStr As String, YearStr As String)
'with much vba afterwards, some of which requires maintaining work.

in Excel, I've tried calling this with
Code:
Sub TestAccessrun()
    Dim apAcc                       As Object
    Dim db                          As Object
    Set apAcc = CreateObject("Access.application")
    apAcc.opencurrentdatabase ("C:\Documents and Settings\xxxxxxx\My Documents\" _
                               & "Distributor Reporting\Refund Report.mdb")
 
 
    'attempt one, doesn't work
    apAcc.Run "DiscReportingMain(""056609149"",""02"",""2011"")"
    'attempt two, doesn't work
    apAcc.Run "DiscReportingMain ""056609149"",""02"",""2011"""
    'attempt three, doesn't work
    apAcc.Run "call DiscReportingMain(""056609149"",""02"",""2011"")"
    'attempt four, doesn't work
    apAcc.Run "call DiscReportingMain ""056609149"",""02"",""2011"""
    'this parameterless sub does work  (TestIt just throws up a msgbox)
    apAcc.Run "TestIt"
    apAcc.Quit
    Set apAcc = Nothing
End Sub

All the not working attempts throw run-time error '2517':
Microsoft Office Access con't find the Procedure '<WHATEVER in. put I string the>'

I also tried testing it on a couple of variations using the module name that the procedure resides in: this approach also broke apAcc.run "ModTest.TestIt"

At the moment, the only thing I can think of (which is too bizarre to be an appropriate method) is to write the parameters to a little table in the database, and call a parameterless sub that reads those values back and calls DiscReportingMain with them.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Err, umm. Figured it out via help in access VBA (I guess I should expand my research techniques past "Google It", "Press buttons until it works")

Code:
apAcc.Run "DiscReportingMain", "056609149", "02", "2011"

works.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top