Getting DoCmd.Hourglass to actually work

P

Paul Ponzelli

I'm using the click event of a label on one form to open another form. It
takes 8 or 10 seconds for that second form to open, because there are
several procedures that run in the Form_Load and Form_Open events.

During that period, I would like the cursor to turn into an hourglass to let
the user know that something is actually going on. In an effort to
accomplish this, I enclosed the code that opens the second form with the
Hourglass method of the DoCmd object. However, when I click on the label,
the hourglass doesn't display for most of the 8 or 10 second wait. Instead,
at the end of the waiting period, the hourglass very briefly flashes (for
less than a second) on the screen right before the second form opens.

Here's the code I'm using.

DoCmd.Hourglass True

stDocName = "frmEmployeeTimeSheet"
stLinkCriteria = "[EmployeeID]=" & "'" & Me![Combo0] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Hourglass False

Can anyone tell me why the Hourglass doesn't display during most of the 8-10
seconds it takes the form to open?

Thanks in advance,

Paul
 
P

Paul Ponzelli

I should mention that I also tried inserting a line of code before the
"DoCmd.Hourglass True" statement to open a form that simply says "Please
Wait," before running the code that opens the second form. But that didn't
work either, because that "Please Wait" form never fully opens either. The
only visible effect of trying to open that intermediate form is that the
barest outline of the form perimeter displays on the screen until the second
form opens entirely. So like the Hourglass, that form isn't displayed to
the user.

Why is it so hard to get VBA to display this visual feedback while the user
has to wait for a form to open?
 
R

Rick Brandt

Paul said:
I should mention that I also tried inserting a line of code before the
"DoCmd.Hourglass True" statement to open a form that simply says
"Please Wait," before running the code that opens the second form.
But that didn't work either, because that "Please Wait" form never
fully opens either. The only visible effect of trying to open that
intermediate form is that the barest outline of the form perimeter
displays on the screen until the second form opens entirely. So like
the Hourglass, that form isn't displayed to the user.

Why is it so hard to get VBA to display this visual feedback while
the user has to wait for a form to open?

I've never had this problem. Are you sure there isn't some other code lines
running prior to these? Is this routine perhaps being called form another
one?

Try adding Me.Repaint.
 
M

Marshall Barton

The reason this is difficult is that Access tries to improve
overall efficiency by running lots of tasks at various
priority levels. If one task has to wait on something (e.g
disk read), another task can proceed instead of sitting
there waiting for the other task to complete. Your VBA
procedure that is opening the form runs at a very high
priority and painting the screen runs at a low priority. In
general this is a very good thing.

The DoEvents method gives you a way for your VBA procedure
to tell the system that it wants to give up the remainder of
it's time slot and let other tasks run. This will not
guarantee that what you want to happen will happen because
the other task may still be waiting for its own events or
something else at a higher priority may take the available
time. Sometimes, using two DoEvents helps.

The Repaint method provides a way to force screen updates to
run immediately, but I don't think that aways achieves the
desired effect either.

I suggest that you first try:
Me.Repaint
If that doesn't do it, then try:
Me.Repaint
DoEvents
--
Marsh
MVP [MS Access]


Paul said:
I should mention that I also tried inserting a line of code before the
"DoCmd.Hourglass True" statement to open a form that simply says "Please
Wait," before running the code that opens the second form. But that didn't
work either, because that "Please Wait" form never fully opens either. The
only visible effect of trying to open that intermediate form is that the
barest outline of the form perimeter displays on the screen until the second
form opens entirely. So like the Hourglass, that form isn't displayed to
the user.

Why is it so hard to get VBA to display this visual feedback while the user
has to wait for a form to open?


I'm using the click event of a label on one form to open another form. It
takes 8 or 10 seconds for that second form to open, because there are
several procedures that run in the Form_Load and Form_Open events.

During that period, I would like the cursor to turn into an hourglass to
let the user know that something is actually going on. In an effort to
accomplish this, I enclosed the code that opens the second form with the
Hourglass method of the DoCmd object. However, when I click on the label,
the hourglass doesn't display for most of the 8 or 10 second wait.
Instead, at the end of the waiting period, the hourglass very briefly
flashes (for less than a second) on the screen right before the second
form opens.

Here's the code I'm using.

DoCmd.Hourglass True

stDocName = "frmEmployeeTimeSheet"
stLinkCriteria = "[EmployeeID]=" & "'" & Me![Combo0] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Hourglass False

Can anyone tell me why the Hourglass doesn't display during most of the
8-10 seconds it takes the form to open?
 
P

Paul Ponzelli

You were both right - the Repaint method will make that intermediate form
visible for the duration. However, I didn't use

Me.Repaint

Instead, I used

forms!frmSaveHoursNotice.Repaint

which makes sense, because "Me" is the calling form, and that's not the form
I'm trying to display. It's the intermediate form "frmSaveHoursNotice"
that's called from the current form (Me), and so I needed to specify which
form I want to "Repaint."

So you gave me the solution by referring me to the Repaint method.

Thank you, gentlemen.

Paul
 
M

Marshall Barton

Paul said:
You were both right - the Repaint method will make that intermediate form
visible for the duration. However, I didn't use

Me.Repaint

Instead, I used

forms!frmSaveHoursNotice.Repaint

which makes sense, because "Me" is the calling form, and that's not the form
I'm trying to display. It's the intermediate form "frmSaveHoursNotice"
that's called from the current form (Me), and so I needed to specify which
form I want to "Repaint."

So you gave me the solution by referring me to the Repaint method.


Glad you got something going.

However, I was thinking of using the Me.Repaint immediately
after the DoCmd.Hourglass True statement. But if you're
happy with the please wait form approach, don't waste time
fooling around.
 
P

Paul Ponzelli

Thanks for the clarification, Marsh.

Yes, I tried both

DoCmd.Hourglass True
Me.Repaint

and

DoCmd.Hourglass True
Me.Repaint
DoEvents

and neither of those got the hourglass to display until the last split
second in the process. But since that's what happens if you just use the
Hourglass method by itself, neither seems to have any effect in this
situation.

Paul
 
M

Marshall Barton

Paul said:
Thanks for the clarification, Marsh.

Yes, I tried both

DoCmd.Hourglass True
Me.Repaint

and

DoCmd.Hourglass True
Me.Repaint
DoEvents

and neither of those got the hourglass to display until the last split
second in the process. But since that's what happens if you just use the
Hourglass method by itself, neither seems to have any effect in this
situation.


I haven't been able to reproduce your situation, so I can't
test all this myself. The only other random thought that
comes to mind is that you may need to move the mouse to get
its pointer redrawn.

The please wait form approach is sounding better all the
time ;-)
 

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