Context: In Microsoft Access, I'm trying to call functions and pass parameters, dynamically, using Application.Run. My code below works in Excel 2013 but does not work in Access 2013.
Code:
Public Sub Test()
Call MethodDynamically("MethodToBeCalled1", "This", "works")
Call MethodDynamically("MethodToBeCalled2", "This", "works", "too")
Call MethodDynamically("MethodToBeCalled3", "This", "works", "too", "as well")
End Sub
Public Sub MethodDynamically(MethodName As String, ParamArray Params() as Variant)
Application.Run MethodName, Params
End Sub
Public Sub MethodToBeCalled1(Params As Variant)
Debug.Print Params(0) & " " & Params(1)
End Sub
Public Sub MethodToBeCalled2(Params As Variant)
Debug.Print Params(0) & " " & Params(1) & " " & Params(2)
End Sub
Public Sub MethodToBeCalled3(Params As Variant)
Debug.Print Params(0) & " " & Params(1) & " " & Params(2) & " " & Params(3)
End Sub
Returns output:
This works
This works too
This works too as well
Error: However in Microsoft Access, the same code gives the error: Compile error: Invalid ParamArray use.
Is there a way of adjusting this code for Access VBA?