Solved

Unable to get VBA code to run from an Access Macro

Posted on 2008-06-25
3
1,205 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:vlvawter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 21866901
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
0
 
LVL 28

Accepted Solution

by:
omgang earned 75 total points
ID: 21866917
To call a sub procedure from a macro, you do what you've already discovered:  create a function to call the sub.  Call the function with the RunCode action in the macro.
OM Gang

PS - sounds a bit like
"swallowed a spider to swallow the fly.  I don't know why she swallowed the fly...."
0
 

Author Closing Comment

by:vlvawter
ID: 31470624
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question