Application.Run Calling a subroutine with a variable

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
189
Hello ~

I have an MS Access application that I administer (Access FE, Azure SQL Server BE).

I have a section of code in which I call a function written in a different module and call it something like this --

iRet = Module1.Function1 (Arg1, Arg2, Arg3)

The above works -- I want to be able to call the same routine, however, using a variable, so instead of "Module1.Subroutine1", something like this --

x = "Module1.Function1"
iRet = Application.Run x, Arg1, Arg2, Arg3

I can't seem to figure out the proper syntax to make this work -- it may not be possible -- but if anyone has any insight it would be greatly appreciated. Thanks!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Using parentheses should work.

VBA Code:
x = "Module1.Function1"
iRet = Application.Run(x, Arg1, Arg2, Arg3)
 
Upvote 0
Unfortunately, that syntax returns error 2517, cannot find the procedure. I'm hoping there must be a syntax that works, but every variation I can think of seem to produce the same error.
 
Upvote 0
Sorry, I only now see that this is an Access VBA question.

In Excel VBA the procedure may be preceded by the name of the code module in which that procedure is located, in Access this will error so the module name must be omitted.
In Access VBA the procedure name may be preceded by the VBA project name ("DBGW" in the image attached).
In case the macro to be invoked is in another database, the macro name needs to be preceded by the project name.

ScreenShot288.png



Both examples should work.
VBA Code:
    Dim Macro As String
    Macro = "DBGW.SomeFunction"
    
    ' example 1
    Access.Application.Run Macro, Arguments
    
    ' example 2
    Dim RetVal As Variant
    RetVal = Access.Application.Run(Macro, Arguments)
 
Upvote 0
Solution
Glad to help and thanks for letting me know (y)
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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