Solved

When should I use DoEvents in Access 2003

Posted on 2010-11-12
5
977 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
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 200 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 150 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

856 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