Solved

Unable to get VBA code to run from an Access Macro

Posted on 2008-06-25
3
1,159 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now