How to make sure that current action completed before moving to next action (1 Viewer)

ria.arora

Registered User.
Local time
Today, 16:55
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?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 18:55
Joined
Jan 20, 2009
Messages
12,852
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
 

mdlueck

Sr. Application Developer
Local time
Today, 04:55
Joined
Jun 23, 2011
Messages
2,631
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:

vbaInet

AWF VIP
Local time
Today, 09:55
Joined
Jan 22, 2010
Messages
26,374
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?
 

ria.arora

Registered User.
Local time
Today, 16:55
Joined
Jan 25, 2012
Messages
109
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

Top Bottom