Update listbox on the fly

StefanOl

Registered User.
Local time
Today, 21:15
Joined
Nov 11, 2009
Messages
15
Dear Sir or Madame

I have a listbox on my form which is used to show "progress" and status messages.

However the listbox is not showing the updates while the VBA code is running but only afterwards (when XP got back the control).

In C/C++ I made a quick Sleep(10) to make it happend but how to do it in MS Access?
My code looks like this

Private Sub SetStatus(Txt As String)
StatusList.AddItem Txt
'Sleep(10) ' A C/C++ try but sleep is not recognized
End Sub


I also want the effect to show the last line in the Listbox, in C/C++ you "told" the listbox to "show" the bottom line
of the listbox by calculating which line, depending on the height of the listbox, should be shown on the top of the visible area.

How do I do this in VBA ?
 
You could try placing DoEvents between each process which usually renders Access until the above process is complete. Then issue the .AddItem line and to ensure that the last line is selected in the list box make the column bound and code Me.ListBox = Txt

David
 
Dear Sir

Thanks a lot, DoEvents works briliant

The code ended up like this

Private Sub SetStatus(Txt As String)
StatusList.AddItem Txt
StatusList.Selected(StatusList.ListCount - 1) = False
DoEvents
StatusList.Selected(StatusList.ListCount - 1) = False
End Sub

The StatusList.Selected statement before the DoEvents makes the scroll more nicer, I am not sure why it works better, probably something windows internal



Regards Stefan
 

Users who are viewing this thread

Back
Top Bottom