Link to home
Start Free TrialLog in
Avatar of gbnorton
gbnortonFlag for United States of America

asked on

Access 2007 function call from Macro

How do I call a function created in Access 2007 Visual Basic with a Macro?

In a test database I created a simple Global function to display a message box.  Now I want to display it by calling it with a macro assigned to a command button.

Thanks,
Brooks
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

in your macro, place

Action
Runcode



Function Name  NameOfFunction()
Or get rid of the macro and call it in VBA

Private Sub cmd_YourButton_Click

    Call NameOfFunction

End Sub

Or if it returns a value, as all functions should, otherwise they should be subroutines

Private Sub cmd_YourButton_Click

    'assumes the function returns an integer
    Dim intRetValue as integer

    intRetValue = NameOfFunction()

End sub




Avatar of gbnorton

ASKER

I get the error: The expression you entered has a function name Microsoft Office Access cannot find.

In Visual Basic I have this code in Module1:
Public Sub Test()
MsgBox "Test"
End Sub

In the Macro editor I have:
Action                      Arguments
RunCode                  Test()

Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the quick help.