Results 1 to 9 of 9
  1. #1
    Middlemarch is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2015
    Posts
    479

    Form programming with a Loop

    My Form's record source is a query and I'd like to move
    through each record, conditionally processing the data.

    If nothing needs doing, how do I move to the next record, in code?
    Keeping the ability to stop if a certain condition is met... and resume the loop later.

    Hope I've explained this OK, I don't normally use Forms (and probably missing something quite basic!)

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Did you try making the default view of the form Single Form? And then cycle through the records with the record selector.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,699
    Well, the form will allow you to progress through the records with the built in navigation buttons at the bottom of the form (if you are in form view). The records available to the form are defined by the query used as the form's recordsource. You can view each record and make changes (or not) and proceed to the next record via the navigation buttons.

  4. #4
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    Yes, but I don't want to click the nav button several thousand times!
    I'm not familiar with moving through a Form, or it's equivalent of .MoveNext but thought there would be one ?

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,699
    You can construct a query for the form's recordsource that will only show records that meet a certain criteria, instead of all the records in the table. Is that what you need?

  6. #6
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    Dave I have done that and set up a Recordset which lets me movenext.
    I had all this working in a VBA module calling a modal Form but didn't like it because I couldn't do anything else (with the Form open)
    So now I'm trying to put all the code in the Form module to avoid that.
    But I'm a bit stuck on how to stop execution while I 'do stuff' with the results. I want to loop through my recordset, conditionally edit some data, then resume the loop.

    I got this idea from Google but it seems a bit odd.. but may work.

    Code:
    Do While KeepGoing = False
        DoEvents
      Loop
    KeepGoing is a global Boolean and set true in a command button.
    Is this an ok concept ? Or a bit mickey mouse ?

    Also, while stepping through my code in the Form, is there any way to see Form view and what's in its controls ?

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Steve Bishop has some excellent, free videos(70+) on Access and vba programming. The list of videos is here.
    There are several on recordsets and loop constructs. I recommend you watch some.

    Also, here is a link to some debugging techniques.

    Good luck.

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,699
    I can't see your form or where your code resides. How do you do your edits? Manually on the form, or via an update query? Is your form in datasheet, single form, or continuous form view?
    But I'm a bit stuck on how to stop execution while I 'do stuff' with the results.
    I'm having a problem visualizing just what you mean by this.

  9. #9
    Middlemarch is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2015
    Posts
    479
    Thanks orange I will take a look. Dave I can't explain it any better. The Form is single view.

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

Similar Threads

  1. Replies: 12
    Last Post: 06-05-2015, 04:27 PM
  2. Replies: 4
    Last Post: 05-29-2015, 09:36 AM
  3. Replies: 13
    Last Post: 08-20-2014, 09:17 AM
  4. Replies: 17
    Last Post: 04-07-2014, 07:48 PM
  5. Db form programming?
    By swat in forum Programming
    Replies: 19
    Last Post: 09-02-2011, 02:22 PM

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