Pausing code

  • Thread starter David C. Holley
  • Start date
D

David C. Holley

Is there a way to cause code to Pause or Wait? I seem to recall reading
something about it sometime ago.

The bigger picture is that I form that pops-up to advise the user that
code is running. The code is triggered on the forms_onCurrent event. On
the form is a text box that displays the progress of the code. For what
ever reason, the form is opening, but the code appears to finish by the
time it opens.
 
G

Guest

What is the background code doing? You may be able to use Do While...Loop,
but it depends on what you are trying to accomplish with the code.
 
D

David C. Holley

The code creates an AppointmentItem in Outlook. I was running the code
directly behind the [frmReservations], however it updates a couple of
fields (outlookEntryId and a few others). Things were getting a bit
wacky so I decided to spin it out to a 2nd Form so that the code could
run on the onAfterUpdate event.
 
G

Guest

One issue, of course, is that Access runs asynchronously with other apps; it
spawns the process and then continues on its merry way with the next line of
code, oblivious to the results of the other process.

In general, one way to handle this is to have a Do While...Loop that checks
for something that does not appear or change until late in the external
process.

Is the problem that Access is attempting to use information that does not
yet exist because the external process has not yet created it? For example,
is your outlookEntryId a reference to the appointment item in Outlook and
Access is attempting to use the value before Outlook has finished creating
the appointment?

I'm not sure how you could apply it to a process that works with Outlook,
but I can give you an example that I use when shelling out to Excel. When I
use Access to manipulate Excel files, the Do While...Loop checks for the
existence of a particular file that is created (by Excel) at the end of the
external Excel process. The code moves so fast that it tries to import before
Excel is finished creating the expected import file. That gets to be pretty
important when what you are trying to do is import the file that results from
the external process...So, the solution is to insert the Do While...Loop
checking for that file and continuing when it is found.

You can also use a variable whose value is set late in the process to check
progress. Do While <variable = False>...Loop and then set the variable to
true after everything else is done, thus allowing the loop to complete.

For testing purposes, at least, just throw in a couple of message boxes that
tell you when you get to various points in the code, and see when they pop
up. That, at least, will tell you how soon each part is being completed.

Not much help, probably, just brainstorming...

David C. Holley said:
The code creates an AppointmentItem in Outlook. I was running the code
directly behind the [frmReservations], however it updates a couple of
fields (outlookEntryId and a few others). Things were getting a bit
wacky so I decided to spin it out to a 2nd Form so that the code could
run on the onAfterUpdate event.
What is the background code doing? You may be able to use Do While...Loop,
but it depends on what you are trying to accomplish with the code.

:
 
D

David C. Holley

Actually, now its a moot point. I had an epiphany - Geico Insurance
saves money - Oh, back to the point, I ended up with a solution that
eliminates the need to have the code pause.
One issue, of course, is that Access runs asynchronously with other apps; it
spawns the process and then continues on its merry way with the next line of
code, oblivious to the results of the other process.

In general, one way to handle this is to have a Do While...Loop that checks
for something that does not appear or change until late in the external
process.

Is the problem that Access is attempting to use information that does not
yet exist because the external process has not yet created it? For example,
is your outlookEntryId a reference to the appointment item in Outlook and
Access is attempting to use the value before Outlook has finished creating
the appointment?

I'm not sure how you could apply it to a process that works with Outlook,
but I can give you an example that I use when shelling out to Excel. When I
use Access to manipulate Excel files, the Do While...Loop checks for the
existence of a particular file that is created (by Excel) at the end of the
external Excel process. The code moves so fast that it tries to import before
Excel is finished creating the expected import file. That gets to be pretty
important when what you are trying to do is import the file that results from
the external process...So, the solution is to insert the Do While...Loop
checking for that file and continuing when it is found.

You can also use a variable whose value is set late in the process to check
progress. Do While <variable = False>...Loop and then set the variable to
true after everything else is done, thus allowing the loop to complete.

For testing purposes, at least, just throw in a couple of message boxes that
tell you when you get to various points in the code, and see when they pop
up. That, at least, will tell you how soon each part is being completed.

Not much help, probably, just brainstorming...

:

The code creates an AppointmentItem in Outlook. I was running the code
directly behind the [frmReservations], however it updates a couple of
fields (outlookEntryId and a few others). Things were getting a bit
wacky so I decided to spin it out to a 2nd Form so that the code could
run on the onAfterUpdate event.
What is the background code doing? You may be able to use Do While...Loop,
but it depends on what you are trying to accomplish with the code.

:



Is there a way to cause code to Pause or Wait? I seem to recall reading
something about it sometime ago.

The bigger picture is that I form that pops-up to advise the user that
code is running. The code is triggered on the forms_onCurrent event. On
the form is a text box that displays the progress of the code. For what
ever reason, the form is opening, but the code appears to finish by the
time it opens.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top