Solved

Unable to get VBA code to run from an Access Macro

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to execute an access 2007 module from vb6 2 32
Trying to open Visio 2013 from a ms access 2016 database 9 30
Programmer 14 46
Access query expression 6 19
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…
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 how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now