问题
I am using VBA in MS Access to select and feed data from table to web service. Data is send in chunks, so xmlhttprequest execution time is quite short. Because script is run in gui thread, during upload Access becomes non-responsible and form does not update.
How can I yield control, so form contents can be updated and have some responsiveness.
Private Sub do_stuff()
lblOperation.Caption = "Doing stuff"
lblProgress.Caption = "0"
Dim rs As Recordset
Dim chunk As String
' ... make query ...
Do While Not rs.EOF
' ... collect data to be sent ...
rs.MoveNext
n = n + 1
If n > 50 Or rs.EOF Then
' send chunk
lblProgress.Caption = "Doing progress..."
send_chunk(chunk)
' Give Access control, so it can pump messages and update form
' Something like Application.ProcessMessages in delphi
chunk = ""
n = 0
End If
Loop
rs.Close
End Sub
回答1:
Try adding a DoEvents statement which "surrenders execution of the macro so that the operating system can process other events".
来源:https://stackoverflow.com/questions/6584046/yield-control-to-ms-access-to-update-gui-and-process-form-events