Doevents vs a timed Pause

ted.martin

Registered User.
Local time
Today, 16:34
Joined
Sep 24, 2004
Messages
743
I am a little confused in the use of Doevents compared to introducing a pre-defined Pause.

For example, I have a form and a subform that has several records; e.g. an Invoice form with the subform of ordered products and prices. The subform calculates the total order value and then returns this number to the main invoice form.

Standard stuff I know but often I have to wait for the subform to complete the addition calculation before (say) command button printing the invoice from the main form.

I usually introduce a 2 second pause before the print command to ensure the subform total calculation has completed.

Would Doevents do the same thing? I don't think so in which case what is Doevents used for?

If someone could explain, that would be great.

Thanks
 
I do not have a complete answer to your question. If you do a google search you will find many explanations.

I too am interested in "delaying" my code for other things to happen thus my interest in your thread.

I just found this http://www.vbforfree.com/?p=157

using the GetInputState() API with doevents looks like a solution that i have not seen before.
 
Thanks all - need to read it all. One more question re: DoEvents: Where does the DoEvents go in the VB code. Before or after the line of code that does something?
 
Thanks - sorry to be a pain but just to make sure I get it right; if I want a Sub to complete before continuing, then I code as follows

Doevents
Call mySub


.... rather than putting the Doevents as the first line in the sub.

thanks
 
That's not a problem. Always good to get things clear than not.

If it's mySub that you want to finish running before releasing processing then you put Doevents after mySub. Sorry I made a mistake there mentioning "before". So:

Call mySub
DoEvents
 
I might get struck drown with lightening here, but I thought I read that the DoEvents is a blunt and bandaid fix where you cannot find something else to use.

Thus at the risk of confusing you maybe in Mysub you could do something else or check something else is done before continuing.

Just a thought.

And by the way I use Doevents alot to slow down my code on automating webpage stuff from VBA so I too take the easy way out and use this bandaid fix sometimes :-)
 
Doevents doesn't cover up or fix anything really. All it does is yield processing to the processor. But for more resource dependent functions you're better off using the timer given in my first post.

Doevents certainly does the job for webpages :)
 

Users who are viewing this thread

Back
Top Bottom