Results 1 to 4 of 4

Thread: Cancelling a Do While Loop

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Ontario, Canada.
    Posts
    85

    Angry

    I have a procedure that steps through a large recordset and updates a progress bar everytime a move next is performed.
    What I want to do is, based on the click of a cancel button I want to be able to exit out of this loop at any time.
    Any ideas?????


  2. #2
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154

    Exit Do ' exits a Do while Loop

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Create a boolean variable with either form-level or global scope depending on your needs, and set it to True when the user clicks cancel. Inside your Do loop put If myBoolean = True Then Exit Do. You will also need to add a DoEvents inside the loop.

  4. #4
    Guest
    One way to do this is to use a public boolean as an additional condition on your recordset loop. If your cancel button is pressed this var gets set to false. You'd want to have a DoEvents inside your loop to make sure that the cancel button actually happens when the loop is running.

    Code:
    blnDoLoop = True  '  This var should be declared as Public.
    Do While Not rstYourRecordset.EOF And blnDoLoop
      '
      '  Whatever...
      '
      DoEvents
      rstYourRecordset.MoveNext
    Loop
    All you'd need in your cmdCancel_Click event is code to change blnDoLoop to false.

    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width