Solved

How to run code during macro on access 2013

Posted on 2014-04-15
4
1,923 Views
Last Modified: 2014-04-16
I have a pretty easy question.  I have some code, here it is for testing:

Function PrintXofX()

Dim intTotalBoxes As Integer
Dim r As Integer
r = 0
intTotalBoxes = InputBox("How Many Total Boxes?")

For r = 1 To intTotalBoxes
    MsgBox (r)
Next

End Function

I just need this code to run during a macro, but I simply can not figure out how.  Can someone help?  I currently have this on a module called PrintXofX, but can move it anywhere if needed.
0
Comment
Question by:dzirkelb
4 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40002687
You should edit the macro where you want to run this code and type

call PrintXofX()

You shouldn't need to move it anywhere.
0
 
LVL 36

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 40002706
The macro action to run a procedure is -- RunCode  -- the code needs to be a function.  A macro cannot directly run a subroutine.  It can run a function that runs a sub if that is what you want but you might as well just put the code into a Function and leave it at that.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 40003703
What exactly is the issue?

Are you receiving errors?  Which ones?

Something to note about your setup -

From your original post, you have a function named PrintXofX


<<< Function PrintXofX() >>> 


You also have this function in a module named PrintXofX

<<<  I currently have this on a module called PrintXofX >>>

This current setup WILL cause errors to the effect of "Ambiguous name detected".

You shouldn't give your functions/subs the same names as their modules, because Access can't distinguish between the module and the functions.

Instead, change your module name from PrintXofX to modPrintXofX, modMyFunctions, modPrintFunctions, etc (ie: any descriptive name that is NOT the same as any of the functions or subs contained within the module).
0
 

Author Closing Comment

by:dzirkelb
ID: 40003883
Thanks guys, that combo of information resolved my issue.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

696 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