How to make sure that current action completed before moving to next action

ria.arora

Registered User.
Local time
Today, 08:57
Joined
Jan 25, 2012
Messages
109
How can I tell my VBA script to wait until previous process / action has finished before continuing with the next process / action?

Seems one process / action is not completed and VBA moves to next process / action which is creating lot of problems.

How to make sure that current process / action completed before moving to next process / action?
 
What you are seeing may be more to do with the consequences of things not completing.
Use this command in places where not enough seems to be happening.

DoEvents
 
Seems one process / action is not completed and VBA moves to next process / action which is creating lot of problems.

The only place I have seen this is when worker code is busy working and the UI goes stale. Otherwise, I have never seen worker code decide to "end early" without finishing all that it was suppose to do.

Use this command in places where not enough seems to be happening.

Code:
DoEvents

Correct. There are a couple of strategic places I have needed to use that. This is the solution to the UI going stale while the worker code is off busy working. For example I needed to add a DoEvents in a loop transferring thousands of records via Stored Procedure. It was necessary to place DoEvents at the end of the loop code which was executing the Stored Procedure. Now the UI stays responsive whereas without DoEvents Windows changed the Access title bar to "Not Responding". However, if I grab the title bar of the form with my mouse, then the worker code stops until I release the window title. Fortunately this code will be running on a computer that no one sits at.
 
Last edited:
Seems one process / action is not completed and VBA moves to next process / action which is creating lot of problems.
If all the processes are within VBA then this isn't possible. If you have spawned a shell process from VBA, it doesn't count in this case. So perhaps you want to explain what exactly you're doing?
 
DoEvent did not work. I have used

Code:
Public Function Pause(intSeconds As Integer)
  ' Comments: Waits for a specified number of seconds
  ' Params  : intSeconds      Number of seconds to wait
  On Error GoTo PROC_ERR
  Dim dateTime As Date
  dateTime = DateAdd("s", intSeconds, Now)
  Do
    Sleep 100
    DoEvents    ' Yield to other processes / programs
  Loop Until Now >= dateTime
PROC_EXIT:
  Exit Function
PROC_ERR:
  MsgBox "Error: " & Err.Number & ". " & Err.Description, , "modDateTime.Pause"
  Resume PROC_EXIT
End Function
 

Users who are viewing this thread

Back
Top Bottom