[AccessD] DoEvents - How should this command be used in Access?

Hale, Jim Jim.Hale at FleetPride.com
Wed May 23 10:23:24 CDT 2007


I have a similar issue where I shell out to run a bat file and then kill
the bat file. The problem is Access continues to run and sometimes
attempts to kill the file before it has finished running generating an
error. I put in a timing loop but this strikes me as a little klutzy. Is
there a better way? TIA

Jim Hale

varAns = Shell(strBatfile)  'run bat file to load prn file to AS400
    Batfile = True
    varTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 3)
    Application.Wait varTime
    Kill strBatfile
    Kill strCmdfile
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Andy Lacey
Sent: Wednesday, May 23, 2007 9:23 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] DoEvents - How should this command be used in
Access?


Dan, FWIW for this kind of operation I set up a loop along the lines of

Do While Dir(strWhatever)=""
DoEvents
Loop

which will keep checking until the file appears BUT I then wrap that in
a timer routine so that it doesn't loop forever. So store the date/time
before you start the loop and after the DoEvents exit the loop smoothly
with a message if it's taken over, say, 15 seconds or whatever you think
reasonable in your case.

--
Andy Lacey
http://www.minstersystems.co.uk



--------- Original Message --------
From: "Access Developers discussion and problem solving"
<accessd at databaseadvisors.com>
To: "'Access Developers discussion and problem solving'"
<accessd at databaseadvisors.com>
Subject: Re: [AccessD] DoEvents - How should this command be used in
Access?
Date: 23/05/07 14:00


John & Jim,

Thanks for your explanations. Would you believe that I now understand
what Help was trying to say?

The problem I was having is when a file was copied from a server to a
client temp folder and then immediately opened by hyperlink.
Occasionally an error would be recorded which said "Can't find file", so
I guessed that the copying by Windows wasn't complete so the file
couldn't be opened. I'll put DoEvents in front of the hyperlink code and
see how it goes!

Thanks!
Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Tuesday, May 22, 2007 9:22 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] DoEvents - How should this command be used in
Access?

Dan,

>Where would it be useful to use the DoEvents command be used in an 
>Access
application?

It is used inside of tight loops when you want to allow the operating
system, or your application, to perform some other business. For example
if you were to open a million records in a table and start formatting
them and pushing them out to a text file, the process of doing so would
lock a lot of computers up tight, in fact pretty much any single core
machine. You could actually try to update a control on a form with
perhaps a line number or something and the text box would not change,
even though you were writing to it. The reason is simply that the VB
application is not yielding any processor cycles back to Windows to
allow it time to refresh the screen.

By placing a DoEvents inside of the loop you can allow the mouse to
move, text boxes to update, even entire other applications to do some
(though still probably not much) processing.

You need to understand what you are doing however when you use DoEvents.
Each call to Doevents can take a fair amount of time, depending on what
else the OS is trying to do. As a result you can slow down the program
quite a bit. If speed nis important however you might want to call
DoEvents every 100th iteration of the loop or something like that.

In the lingo, there is "pre-emptive multi-tasking" (the OS slices up
time and assigns slices to tasks) and co-operative multi-tasking (each
task yields control occasionally back to the OS). DoEvents is
co-operative multitasking. The Windows OS is supposed to use pre-emptive
multi-tasking but in fact it does so very poorly.

John W. Colby
Colby Consulting
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Dan Waters
Sent: Tuesday, May 22, 2007 8:48 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] DoEvents - How should this command be used in Access?

Hello to everyone!

Where would it be useful to use the DoEvents command be used in an
Access application?

Thanks!
Dan Waters

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



















































































































































































--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

________________________________________________
Message sent using UebiMiau 2.7.2

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

***********************************************************************
The information transmitted is intended solely for the individual or
entity to which it is addressed and may contain confidential and/or
privileged material. Any review, retransmission, dissemination or
other use of or taking action in reliance upon this information by
persons or entities other than the intended recipient is prohibited.
If you have received this email in error please contact the sender and
delete the material from any computer. As a recipient of this email,
you are responsible for screening its contents and the contents of any
attachments for the presence of viruses. No liability is accepted for
any damages caused by any virus transmitted by this email.




More information about the AccessD mailing list