Solved

How to run code during macro on access 2013

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

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Outlook Free & Paid Tools
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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 …

770 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