Pausing a Loop, Threading Etc

chappy

Registered User.
Local time
Today, 19:38
Joined
Nov 5, 2003
Messages
30
Is there a good way to implement threading with vba? I have a program that runs some loops that can take a few minutes to run sometimes. Is there any way to implement a "pause" button? Visual Basic doesn't really have built in threading, so the moment a loop is running, the program won't respond to any object events such as button clicks. Any suggestions?

-Chappy
 
Try placing DoEvents within the loops, it should be covered in the on-line help of your version of Access.

Hope that helps.

Regards,
Chris.
 
Chris... correction....

I tried that, and it does 'pause' the code.
Simple test setup...

form with 2 command buttons...

Private Sub Command0_Click()
spendtime
End Sub

Private Sub Command1_Click()
MsgBox "Paused"
End Sub


Public Function spendtime()
Dim i, s As Long

For i = 1 To 10000
s = i + i
DoEvents
Next i
MsgBox s

End Function

Click button one, and then click button two. Button one code is paused, but will finish after button two is thru.
 
Last edited:
Tried it and is seems OK in A97.

I don’t think your code has stopped, just taking a long time to run.

Little demo attached.

Regards,
Chris.
 

Attachments

Users who are viewing this thread

Back
Top Bottom