?
Solved

How to run code during macro on access 2013

Posted on 2014-04-15
4
Medium Priority
?
2,094 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 40

Assisted Solution

by:PatHartman
PatHartman earned 1000 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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

807 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