0

In VBA (Access) I created a classmodule called "ZFormHelperClass" with a public function "FromStart"

Public Function FromStart(ByVal name As String, Optional ByVal lfd As Long = InvalidLfd, Optional ByVal centerd As Boolean = False) As ZFormContainerClass

    'Do something

End Function

I use a public function in a module as a constructor for this class:

Public Function ZFormHelper() As ZFormHelperClass

    Set ZFormHelper = New ZFormHelperClass

End Function

Then I tried to use a macro ("Test") to call this function in "Run Code" (or "Execute Code") like this:

=ZFormHelper.FromStart("Start", -1, True)

But it does not even let me save the Macro (Error: german version of: "Invalid value form the functionname argument"). I had to create a function do do this.

Function doStart()

    Call ZFormHelper.FromStart("Start", -1, True)

End Function

So I wonder why this is the way it is and if there is a way to call a class function directly without having to create a dummy-function.

Gener4tor
  • 414
  • 3
  • 12
  • 40
  • If you are capable of creating and using a class module, I have to question why you would need to involve a macro at all? – Minty Jul 26 '18 at 11:40
  • 1
    I am working with legacy-software. This problem is the result of a refactoring. In this case the macro is named "Autokeys" and is called when the user presses crtl + Y – Gener4tor Jul 26 '18 at 11:50
  • btw. I have got the same problem when trying to call the function out of an "OnAction"-Trigger in a ribbon-button... – Gener4tor Jul 26 '18 at 12:00
  • Ah okay. I think the correct Macro action is RunCode - I can't find an execute option. What version of Access are you using ? – Minty Jul 26 '18 at 12:03
  • According to MS you don't use the = in the macro ; https://msdn.microsoft.com/en-us/library/office/ff834373.aspx?f=255&MSPPError=-2147217396 – Minty Jul 26 '18 at 12:10
  • 1
    @Minty: RunCode seems correct (In german its "Ausführen Code" which literally means "Execute Code"). Im using Office 16. Removing the = does not change much. Now I can save the macro but when starting it, I get an error: "cant find the given Name "ZFormHelper"" (+ a lot of german text which explains nothing for me). – Gener4tor Jul 26 '18 at 12:47

1 Answers1

1

According to Albert Kallal you can't.

Review his comment here MS Access RunCode Macro cannot find my procedure

Minty
  • 1,616
  • 1
  • 8
  • 13