Results 1 to 8 of 8
  1. #1
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151

    How do I program a "For 1 to X" type loop in a macro?


    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.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

  3. #3
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    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.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

  7. #7
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    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.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-10-2012, 02:51 PM
  2. Replies: 4
    Last Post: 08-17-2012, 05:27 PM
  3. Replies: 5
    Last Post: 02-23-2011, 04:03 PM
  4. Need to update an ancient Access97 "program".
    By Hilton in forum Programming
    Replies: 1
    Last Post: 05-26-2010, 04:47 AM
  5. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums