Solved

When should I use DoEvents in Access 2003

Posted on 2010-11-12
5
941 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:ssmith94015
5 Comments
 
LVL 11

Assisted Solution

by:LambertHeenan
LambertHeenan earned 150 total points
Comment Utility
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
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 200 total points
Comment Utility
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
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 150 total points
Comment Utility

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
 

Author Comment

by:ssmith94015
Comment Utility
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
 

Author Closing Comment

by:ssmith94015
Comment Utility
Excellent information and thank you for teaching me.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now