Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeating a macro with RunMacro

Status
Not open for further replies.

bhunter

Programmer
Jul 27, 2000
36
US
I am using the RunMacro command to run a macro a certain number of times.  I am using it to add some records to a table.  Is there a variable that keeps track of how many times the macro has run?  I need to compare that value with another number (the max. # of times I want it to run) in order to create my repeat expression?  I haven't been able to figure out how to reference the counter variable that is incremented each time the macro runs.  I assume that this number is available somewhere.  I would greatly appreciate it if someone could tell me how to do this.
 
I don't know how you could do it in a macro, but you could do it in code easily enough.<br><br>On the On Click of a button, put the following:<br><br>==========<br>Public Sub <b>YourButton</b>_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim maxNum As Integer, i As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;maxNum = InputBox(&quot;How many times do you want this to run?&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;If maxNum &gt; 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For i = 1 To maxNum<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.RunMacro &quot;<b>YourMacroName</b>&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next i<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Sub<br>==========<br><br>close and save. Click the button, and you will get an input box to tell the process how many times to run, and it will run until it reaches that number. <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top