Solved

Unable to get VBA code to run from an Access Macro

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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