Cancel Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I run a job that takes a long time to process. While it is running, I need
to put a "Cancel" Button to stop the processing if necessary.
It is something like when you run the "DoCmd.OpenReport ", the system will
popup a cancel button, and while the background is processing, you have to a
chance to cancel the processing.

If you have NWIND.mdb, have a look at Forms/Orders/Click on the "Print
Invoice." icon, and you will be prompted with a box to ask you to vote. How
do you do this access?

Regards
 
Tan said:
I run a job that takes a long time to process. While it is running, I need
to put a "Cancel" Button to stop the processing if necessary.
It is something like when you run the "DoCmd.OpenReport ", the system will
popup a cancel button, and while the background is processing, you have to a
chance to cancel the processing.

If you have NWIND.mdb, have a look at Forms/Orders/Click on the "Print
Invoice." icon, and you will be prompted with a box to ask you to vote. How
do you do this access?


Depends on what you're doing. Then general idea is to open
a non-dialog form at the beginning or your process. Then,
at strategic places in your process, check if the form's
cancel button was used and bail out of your process. If you
process is a single long running Access operation such as a
complex query, the you may need to resort to the built-in
Control+C keyboard method of interrupting the process.
 
Just create an ordinary form with a button captioned
"Cancel". The button's click event can make the form
invisible, set a specific value in a hidden text box, or
even close the form. Then your strategically placed code
can check for the condition to see if it should bail out of
the procedure.

You may want to set the form's Popup property so it doesn't
get hidden behind something else.

Don't open the form using the acDialog option because that
prevents any code from executing. (You can not use a MsgBox
because they are always in dialog mode.)
 
Do you have a sample I can use? Just take the example of the print job - I
am doing some processing that takes a long time (maybe just a Timer than
loops for 10 min), and I need a button to cancel it at any 1 point in time.

Marshall Barton said:
Just create an ordinary form with a button captioned
"Cancel". The button's click event can make the form
invisible, set a specific value in a hidden text box, or
even close the form. Then your strategically placed code
can check for the condition to see if it should bail out of
the procedure.

You may want to set the form's Popup property so it doesn't
get hidden behind something else.

Don't open the form using the acDialog option because that
prevents any code from executing. (You can not use a MsgBox
because they are always in dialog mode.)
--
Marsh
MVP [MS Access]

Thanks! But how do I create a non-dialog form and yet has a "Cancel" command
button?
 
I don't see how getting a timer involved will help this
kind of thing.

The general code I was suggesting would be along these
lines:

DoCmd.OpenForm "frmCancel"

'start your process
. . .
If Forms!frmCancel.Visible Then
DoCmd.Close AcForm, "frmCancel"
Exit Sub
End If
'continue your process
. . .
If Forms!frmCancel.Visible Then
DoCmd.Close AcForm, "frmCancel"
Exit Sub
End If
. . .

The Click event for the "Cancel" button on frmCancel would
just be:
Me.Visible = False

How you get into the details is highly dependent on what you
are doing and we can not write your program for you, so I
don't know how to be more specific.
 

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

Back
Top