Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

When should I use DoEvents in Access 2003

Posted on 2010-11-12
5
Medium Priority
?
1,032 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 600 total points
ID: 34122332
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 - Microsoft MVP, Access and Data Platform) earned 800 total points
ID: 34122355
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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 600 total points
ID: 34122375

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
ID: 34122579
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
ID: 34122620
Excellent information and thank you for teaching me.
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

972 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