I want to use a form to get user input for the number of times (x) that I need to repeat an action. Then I want to do a "For 1 to X" loop in a macro. I need help on the command to use in the macro. Thanks.
I want to use a form to get user input for the number of times (x) that I need to repeat an action. Then I want to do a "For 1 to X" loop in a macro. I need help on the command to use in the macro. Thanks.
Google: Access macro do while
See if this helps http://support.microsoft.com/kb/209790
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Thanks, but no that didn't help. I had looked at that before. I understand the different types of loops from previous languages I've worked with but in the macro editor in Access, I simply can't find any actions that are for loops (do while, do .. loop until, for ... next). This is where I am stuck.
I never use macros so just tried to find the commands described in that article and not seeing them. If those structures are no longer available with Access then must use VBA.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
I don't use macros either, but I found this with google
http://support.microsoft.com/kb/90815
Just looked at this in more detail --- it was for Access 1 and 2
Sorry about that.
I did find this http://www.access-programmers.co.uk/...d.php?t=212801
So now we have 2 KB articles with the same instructions which appear to be pre-Access2007 language. I am afraid, msmithtlh, those articles demonstrate the only ways a macro can execute looping logic. VBA code so much easier. However, I mostly followed the instructions for the first example and it works. I didn't know how to create a macro group so I saved two macros and instead of calling For_Next_Loops.Loop1, just called Loop1. Referencing input textbox instead of static number in RepeatCount argument did not work - no errors, nothing happens. So I tried example 2. When you create new macro, click ShowAllActions on the ribbon to expose the SetValue action in the list. Instead of <=10 in the RepeatExpression argument I referenced the input textbox. This works. Code loops until counter textbox is greater than input textbox.
Last edited by June7; 04-12-2013 at 10:59 PM.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Sorry, June7, your comments above are confusing. What samples are you referring to? If I need to use VBA code for the loop, can I also use a macro, and have either the macro call the VBA code, or vice versa? If yes, please give specifics for how to do it. Thanks.
I am referring to the example macro code in the link I referenced. I don't even use macros but I was able to follow that article well enough to reproduce the behavior.
AFAIK, macros can call Function, not Sub, procedure, and I think VBA can call a maco. But if you go with VBA why have macro at all? Since I don't know why you want loop can't say must use VBA, but VBA is easier for me.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.