Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316

    Unanswered: Visibly updating a text box while a loop is running

    I have a text box on a form called txtRecordsRemaining, with a format of General Number. I am using the following code so that once each record has been processed in the loop, txtRecordsRemaining is reduced by one (so I have a visible counter on screen):

    Code:
    x = rs1.RecordCount
    txtRecordsRemaining = x
    
    Do While Not rs1.EOF
        'Do processing
    Loop
    However, this doesn't work. Anyone with any ideas as to why?

  2. #2
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    You need to put the counter inside the loop. For example:

    Dim lngRecordCounter AS Long
    lngRecordCounter = 1
    Do Until rst.EOF
    ' do processing
    Me("txtRecordsRemaining").Value = lngRecordCounter
    lngRecordCounter = lngRecordCounter + 1
    ' To show the changes if you have locked the screen you will need to repaint the screen to show the changes
    Me.Repaint
    rst.MoveNext
    Loop

    Justin

  3. #3
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    Cheers, that worked a treat. I knew about my counter needing to be inside my loop, it was the Paint I didn't know about.

  4. #4
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    I noticed that the Me.Repaint method doesn't seem to account for all eventualities. For example, if you click anywhere on the screen, or move to another applicationsion, then come back to Access, the counter stops, even though the loop is still going. Is there a way to counter this interuption?
    Last edited by bcass; 03-04-05 at 11:44.

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    at the cost of dropping clock cycles to other running processes, try
    doevents
    before the repaint

    izy
    currently using SS 2008R2

  6. #6
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    Thanks, that seems to work. Just need to disable controls while the loop is running.

Posting Permissions

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