Yields execution so that the operating system can process other events.
DoEvents( )
The DoEvents function returns the number of open forms in standalone versions of Visual Basic, such as Visual Basic, Standard Edition. DoEvents returns 0 in all other applications.
DoEvents passes control to the operating system. Control is not returned until the operating system has finished processing the events in its queue and, for Microsoft Windows only, all keys in the SendKeys queue have been sent.
If parts of your code take up a lot of processor time, use DoEvents periodically to relinquish control to the operating system so that events, such as keyboard input and mouse clicks, can be processed without significant delay.
Caution Make sure the procedure that has given up control with DoEvents is not executed again from a different part of your code before the first DoEvents call returns; this could cause unpredictable results. In addition, do not use DoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.
SendKeys Statement.
In Microsoft Access, the DoEvents function is ignored if you use it in:
If you include the DoEvents function in any of these, Microsoft Access will not relinquish control to the operating system.
This example uses the DoEvents function to cause execution to yield to the operating system once every 1000 iterations of the loop. DoEvents returns the number of open Visual Basic forms, but only when the host application is Visual Basic.
' Create a variable to hold number of Visual Basic forms loaded ' and visible.OpenFormsI = 1 To 150000 ' Start loop. If I Mod 1000 = 0 Then ' If loop has repeated 1000 times. OpenForms = DoEvents ' Yield to operating system. End IfI ' Increment loop counter.