Cancelling a current process...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

I have an application where the user clicks on a 'Calc' button to calculate
a home price. This procedure takes some time because there are many details
to go through befoire a price can be displayed. When they click the button,
I display a pop-up form with a process bar on it - to indicate the
completeness of the operation....

What I would like is to add a 'Cancel' button to this form so that if need
be the user can cancel that operation to maybe modify some pricing etc...
that they maybe forgot to do...

What do I have to do to make sure the cancel button is accessible and the
user can click it at any point in the calculation process? I added a cancel
button as a test and attempted to click on it. Eventually it did click, but
took some time. I would like it to click right away if possible.

What I was planning on doing was to use a public variable so that when they
click the 'Cancel' button, I would set a public variable to 'TRUE'. Then in
the routines handling the calculations, I would check that public variable
in strategic locations. If it happens to be set to "true", I would exit the
calc procedure altogether. It's a little tricky though because the calc
procedure is made up of many subs and functions...

Any help would be most helpful...

Thanks,

Brad
 
enclose whatever procedure is the main processing loop for the calculation
with a do loop that has a check for a specific variable. Set the value of
the variable in the button's click event. Dim the variable at the module
level. Use DoEvents to allow the OS to give other events a chance:

Dim blnStopNow as Boolean

'where your process happens.

Do While True
'Do a Process here
DoEvents
If blnStopNow Then
Exit Do
End If
Loop

In the button click event

blnStopNow = True
 
Back
Top