Solved

How to run code during macro on access 2013

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

My experience with Windows 10 over a one year period and suggestions for smooth operation
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

706 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

15 Experts available now in Live!

Get 1:1 Help Now