When should I use DoEvents in Access 2003

I have a rather lengthy procedure in ACCESS 2003 and was wondering what the benefit would be of using a DoEvents.  I do not understand the advantage - does thi sallow the user to do other things in other applications while the procedure is running?  If the user does open other applicatoins, the ACCESS procedure simply bogs down and takes longer.  This is inherited code and I am trying to streamline and make more efficient.
ssmith94015Asked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Connect With a Mentor Commented:
DoEvents allow Windows to 'catch up' with such things as pending display updates and other such house keeping.

Typical use of DoEvents is inside a Loop that is doing a lot of stuff, especially if in the loop ... you are maybe updating a text box on a form with some sort of 'status' indication.  W/O DoEvents, the text box will probably not show the updated status.

There are many other examples.

So yes ... it is VERY beneficial ...

mx
0
 
LambertHeenanConnect With a Mentor Commented:
DoEvents simply allows other threads/processes to get some porcessor time. So when you have tight loops of code running Access will typically not update the screen while the code runs. When you include DoEvents statements inside the loop(s) then the screen will update and give some visual feedback to the user. Otherwize they might mistakenly think that the application has frozen up.

Users can always use other applications, and DoEvents does not have any impact on that. Nor does it make the Access code run any faster. As I said it's really just about having the screen update. Without it when switching applications the Access window may show up blank, which could worry the user.
0
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:

see this links, to understand the function

Definition of DoEvents in Visual Basic for Applications
http://support.microsoft.com/kb/118468

DoEvents Function
http://msdn.microsoft.com/en-us/library/aa168649.aspx

      "Caution   Any time you temporarily yield the processor within an event procedure, make sure the procedure is not executed again from a different part of your code before the first 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."



Using DoEvents

http://msdn.microsoft.com/en-us/library/aa231254%28VS.60%29.aspx



How To Determine the Differences Between DoEvents and Sleep
http://support.microsoft.com/kb/158175






0
 
ssmith94015Author Commented:
Thank you all  This really helped.  I have a progress bar that keeps the user informed of what is going on, so it appears that I can dispense with the DoEvents as I have other visual clues for the user.  Howver, updating a text box with DoEvents help would be helpful in another application.  Am splitting as each of you gave me a good prespective.
0
 
ssmith94015Author Commented:
Excellent information and thank you for teaching me.
0
All Courses

From novice to tech pro — start learning today.