How to halt a procedure

J

JackEbayB

I have a procedure that stores and retrieves image files. The process could
be a long one due to the number and size of the image files and so I need a
way of allowing the user to press the Esc key (or any key for that matter) to
programmatically cancel the process. The event "On Key Press" is not being
recognized. Anyone know how this can be done? Thanks!
 
R

RoyVidar

JackEbayB wrote in message said:
I have a procedure that stores and retrieves image files. The process could
be a long one due to the number and size of the image files and so I need a
way of allowing the user to press the Esc key (or any key for that matter) to
programmatically cancel the process. The event "On Key Press" is not being
recognized. Anyone know how this can be done? Thanks!

If you are using the forms key press event, I think you'll also need to
set the forms keypreview property to yes.
 
J

JackEbayB

Thanks for your response. I should have mentioned that the Ctrl+Break option
is not a good one because I would like it to cancel out of the procedure more
gracefully and not have the user face the question of ending it or debugging.
Also, I have the Key Preview set to Yes. If you have any more wisdom to
share please do. Thanks!
 
A

Albert D.Kallal

The on key process WILL be recognized if you give ms-access a chance to grab
a "breath" of air, and process pending events.

In your code that process the images, if each loop takes a bit of time, then
simply put in a

doEvents

The above will flush out, and process the event queue.

However, if the loop is a very fast tight loop, then be careful.

For example, you can easily run a loop to 10, or even 100 million in a few
seconds. That same loop with only 10,000 iterations with a doevents in the
loop WILL TAKEN LONGER then the 100 million loop.

So, test with a DoEvevts in each iteration of the loop. If you are only
processing a few 1000 records..then this approach is ok...

If you have a large number of items..then you need put in some code to
"test" for every 100 or 1000 iterations..and THEN execute the doEvents.

So, just keep mind, that DoEvents does have some "cost" in terms of time for
the loop...

You can have the key down code set a global var that the processing loop
tests for.


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyEscape Then

KeyCode = 0

If MsgBox("do you want to stop the procssing?", _
vbQuestion + vbYesNo, "Stop?") = vbYes Then

gblStop = True
End If

End If

End Sub


Then, in your image loop...you can go:

if gblStop = True then
exit loop.........
 
J

JackEbayB via AccessMonster.com

Awesome! It was DoEvents that did the trick. Thank you so very very much.
May you and your descendants to the 1000th generation be blest!
 

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