Solved

How to run code during macro on access 2013

Posted on 2014-04-15
4
1,910 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

831 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