Repaint does not always work RRS feed

  • Question

  • I've got some code that opens a record set and updates the value of a text box on a form with the contents of the current records field in a Do While loop

    'Open the record set and move last then move first to get the record count

    Do While bla bla
      'some code
      txtStuff.Value = rs![field name]
      'MsgBox "Continue"
      'some code

    The above does not consistently change the value in the text box unless I enable MsgBox "continue"

    So I'm guessing it is a timing issue... but I've tried a loop right after Me.Repaint counting n from 1 to 1,000 but that does not help.

    Any suggestions? Thanks

    Sunday, July 26, 2015 9:00 PM

All replies

  • The above does not consistently change the value in the text box unless I enable MsgBox "continue"

    Hi Fran,

    You can try to use  DoEvents  after  Me.Repaint.


    Sunday, July 26, 2015 9:20 PM
  • Hi Fran,

    As i can only see part of your code I cannot be sure of the issue.

    The value in txtStuff would be changing very rapidly with each record!

    Is txtStuff a Bound Field? If so it will need time to write and update.

    Perhaps your need to do something with the result rather than just update a single field?


    txtStuff.Value = txtStuff & ", " & rs![field name]

    Brian, ProcessIT- Hawke`s Bay, New Zealand

    Sunday, July 26, 2015 9:25 PM
  • Imb, I'm concerned about using DoEvents after reading some stuff on line.

    Brian, txtStuff is not a bound field and your suggested code

    txtStuff.Value = txtStuff & ", " & rs![field name]

    places the value of the field into textbox twice... for example if rs![field name] returns the contents of the specified field for the current record and that content was "BlaBlaBla" then the text box would display BlaBlaBla.BlaBlaBla

    Allow me to attempt to restate the issue:

    'we are going to step through a record set
    'display the contents of a specified field from the current record in a text box on the form
    'call a function that will not return for a few seconds
    'loop and repeat for each successive record until done
    'kind of like the below

    Do While Not rs.EOF
      'some code
      txtStuff.Value = rs![field name] 'display the contents of the specified fld in the txt box named txtStuff on the form
      'MsgBox "Continue" 'if we uncomment this code the text box gets reliably
      'call a function that will not return for a few seconds

    The text box txtStuff does not always update reliably and show the contents of the specified field of the current record.

    Thinking it was a timing issue we have inserted code after Me.Repaint in an attempt to let the text box get updated but nothing yeilds reliable results.

    Then we inserted this just after the Me.Repaint line

    strFieldContents = rs![field name]
    i = 0
    Do While txtStuff.Value <> strFieldContents
        For i = 1 To 10
        i = i + 1
        Next i
    Debug.Print i

    and surprisingly the immediate window displays all zeros... meaning the For Next in the Do While never ran
    and that means to me that the contents of the text box txtStuff was updated to rs![field name]
    but for some reason the text box on the form does not reliably get updated to actually display the fields contents.

    If anyone can offer any help on this it would be greatly appreciated as I have a few hours invested now and seem to be stumped.


    Monday, July 27, 2015 11:36 AM
  • Hello Fran,

    Instead of posting pseudo code, please post your actual procedure(s) so that we can see all that is involved and what may be causing your problem. 


    Monday, July 27, 2015 3:55 PM
  • Hi Fran,

    Ok so you want to show the user ALL the Values in the Recordset, one at a time, in the SAME textbox?

    I suggest that you need to use the Windows API Sleep. This will allow the OS to continue to run (and support screen redraw) without being busy processing your loop.

    Private Declare Sub Sleep Lib "kernel32" (ByVal lngMS As Long) Sub ...

    do while not rs.eof txtStuff.Value = rs![field name]


    Call Sleep(10000) 'Pause for 10 seconds'


    Loop end Sub

    Brian, ProcessIT- Hawke`s Bay, New Zealand

    • Edited by ProcessIT Monday, July 27, 2015 9:01 PM spelling
    Monday, July 27, 2015 9:00 PM
  • Hello Fran,

    Did you ever reach a resolution to your problem here?

    Friday, July 31, 2015 2:14 PM