Link to home
Start Free TrialLog in
Avatar of vlvawter
vlvawter

asked on

Unable to get VBA code to run from an Access Macro

I've never used the Macro object in Access, but I've inherited a project, and I need to.  I cannot get the runcode option to run a UDF, getPeachtree().

The macro name is importPeachtree; so, there is no name conflict.  (The module that has the code with other code is Importing, again, no name conflict).
The action is RunCode.
The function name for the RunCode is getPeachtree.  I have done it with () and without.  The () have had no space after getPeachtree() as well as a space getPeachtree ().

Regardless of what I do, the error comes up, "The expression you entered has a function name that [my program name] can't find."

I have converted the macro to VB, which is in the snippet.  When I go into the VB editor and run the snippet, everyone works fine!

This has to be a common problem.  What do I do fix this so that I don't have to throw my laptop through a window?
Function Switchboard_importPeachtree()
On Error GoTo Switchboard_importPeachtree_Err
 
    getPeachtree
 
 
Switchboard_importPeachtree_Exit:
    Exit Function
 
Switchboard_importPeachtree_Err:
    MsgBox Error$
    Resume Switchboard_importPeachtree_Exit
 
End Function

Open in new window

Avatar of omgang
omgang
Flag of United States of America image

I suspect the problem is with the getPeachtree procedure.  Is it a sub or function?  I.e. when you view it in the VB editor is it

Public Sub getPeachtree()
or
Public Function getPeachtree()

The RunCode action in a Macro can only call a function.

OM Gang
ASKER CERTIFIED SOLUTION
Avatar of omgang
omgang
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
Avatar of vlvawter
vlvawter

ASKER

I'm well aware of the difference between sub and func, and I saw the word function in the macro help, but I horribly assumed it was used in a general and not a specific sense.  Thanks.  It works with no problem now.