Cancel Button not working

  • Thread starter Jesse via AccessMonster.com
  • Start date
J

Jesse via AccessMonster.com

I have a message pop up when a command button is pressed to run a report. The
problem is the cancel button is not cancelling the action. It still runs the
report like you pressed ok. What am I missing?

Response = MsgBox("Approximate wait time is 5 minutes." _
& Chr(10) & Chr(13) & _
"Push OK to continue,Cancel to Quit", 1)
 
L

Linq Adams via AccessMonster.com

Perhaps you need to go back and look at Access Help for MsgBox!

Your posted code doesn't even include what buttons you want to appear on the
messagebox, much less what you want to do according to the button pushed! All
you're doing is presenting a message!
 
J

Jesse via AccessMonster.com

Ok, All im trying to accomplish is a msg that pops up and states a run time
then as an OK or Cancel button. If the ok is pressed then continue with the
command action or if cancel is pressed then cancel the command action.
 
D

Douglas J. Steele

Actually, the posted code DOES include what buttons should appear. The ", 1"
after the text corresponds to vbOkCancel.
 
D

Douglas J. Steele

Private Sub MyButton_Click()
Dim Response As Long

Response = MsgBox("Approximate wait time is 5 minutes." _
& Chr(13) & Chr(10) & _
"Push OK to continue,Cancel to Quit", vbOkCancel)
If Response = vbOk Then
DoCmd.OpenReport ...
End If

End Sub
 
L

Linq Adams via AccessMonster.com

Sorry, Doug, I missed that! But, of course, the code did nothing depending on
which button was pressed!
 
J

Jesse via AccessMonster.com

Thank you for your help Douglas. I have incerted the code you provided and I
am recieving the same results as my code. Upon clicking the ok button the
report runs. But if the cancel button is click the report still runs. I would
like the cancel button to cancel the action and return to the form. Here is
what I have on my report open. Again thank you for the help.

Private Sub Report_Open(Cancel As Integer)

Dim Response As Long

Response = MsgBox("Approximate wait time is 5 minutes." _
& Chr(13) & Chr(10) & _
"Push OK to continue,Cancel to Quit", vbOKCancel)
If Response = vbOK Then
DoCmd.OpenReport "Picks Hourly - 24hr"
End If
DoCmd.Maximize
End Sub
Actually, the posted code DOES include what buttons should appear. The ", 1"
after the text corresponds to vbOkCancel.
Perhaps you need to go back and look at Access Help for MsgBox!
[quoted text clipped - 3 lines]
All
you're doing is presenting a message!
 
J

Jesse via AccessMonster.com

I have fixed my problem with a different path. I placed the code on the
command click instead of having it on the report open. It works the way its
suppose to now. Thank you again for your help.
Thank you for your help Douglas. I have incerted the code you provided and I
am recieving the same results as my code. Upon clicking the ok button the
report runs. But if the cancel button is click the report still runs. I would
like the cancel button to cancel the action and return to the form. Here is
what I have on my report open. Again thank you for the help.

Private Sub Report_Open(Cancel As Integer)

Dim Response As Long

Response = MsgBox("Approximate wait time is 5 minutes." _
& Chr(13) & Chr(10) & _
"Push OK to continue,Cancel to Quit", vbOKCancel)
If Response = vbOK Then
DoCmd.OpenReport "Picks Hourly - 24hr"
End If
DoCmd.Maximize
End Sub
Actually, the posted code DOES include what buttons should appear. The ", 1"
after the text corresponds to vbOkCancel.
[quoted text clipped - 4 lines]
 
B

BruceM via AccessMonster.com

You would have needed Cancel = True in the code to cancel the report opening.

I have fixed my problem with a different path. I placed the code on the
command click instead of having it on the report open. It works the way its
suppose to now. Thank you again for your help.
Thank you for your help Douglas. I have incerted the code you provided and I
am recieving the same results as my code. Upon clicking the ok button the
[quoted text clipped - 20 lines]
 
B

BruceM via AccessMonster.com

I meant to mention that Douglas posted code for the Click event of a command
button, not the report's Open event. You were trying to open a report in its
own Open event.
I have fixed my problem with a different path. I placed the code on the
command click instead of having it on the report open. It works the way its
suppose to now. Thank you again for your help.
Thank you for your help Douglas. I have incerted the code you provided and I
am recieving the same results as my code. Upon clicking the ok button the
[quoted text clipped - 20 lines]
 
J

Jesse via AccessMonster.com

Thank you for your input. To get it to work on the report open I used this.

Dim Response As Long

Response = MsgBox("Approximate wait time is 5 minutes." _
& Chr(13) & Chr(10) & _
"Push OK to continue,Cancel to Quit", vbOKCancel)
If Response = vbCancel Then
DoCmd.CancelEvent
End If

The docmd.canceEvent works good except it maximizing the form. I have the
code on the report to maximize on open and restore on close to restore the
form to the size i have it. But if you press the cancel button it still
maximizes the form and does not complete the restore docmd. Not a huge deal
but still would be nice to have it work clean. If you have any insite on this
issue I would be happy to listen and learn. Thanks
I meant to mention that Douglas posted code for the Click event of a command
button, not the report's Open event. You were trying to open a report in its
own Open event.
I have fixed my problem with a different path. I placed the code on the
command click instead of having it on the report open. It works the way its
[quoted text clipped - 5 lines]
 
B

BruceM via AccessMonster.com

Maximizing which form? Are you referring to code in the command button that
opens the report? You could try Cancel = True rather than DoCmd.CancelEvent,
but I doubt it will make a difference?
Thank you for your input. To get it to work on the report open I used this.

Dim Response As Long

Response = MsgBox("Approximate wait time is 5 minutes." _
& Chr(13) & Chr(10) & _
"Push OK to continue,Cancel to Quit", vbOKCancel)
If Response = vbCancel Then
DoCmd.CancelEvent
End If

The docmd.canceEvent works good except it maximizing the form. I have the
code on the report to maximize on open and restore on close to restore the
form to the size i have it. But if you press the cancel button it still
maximizes the form and does not complete the restore docmd. Not a huge deal
but still would be nice to have it work clean. If you have any insite on this
issue I would be happy to listen and learn. Thanks
I meant to mention that Douglas posted code for the Click event of a command
button, not the report's Open event. You were trying to open a report in its
[quoted text clipped - 5 lines]
 
J

Jesse via AccessMonster.com

I have a form that is built as a switchboard. When I press a command it
follows the handle number then opens a report. On the report properties I
have event procedures on the "On Open" and "On Close". the on open I tell it
to maximize and on the on close I tell it to restore. I have the form not
maximized in the access database but when you maximize a report it maximizes
the form unless you tell it to restore on close. then it puts the form window
back to the size you have previously set. So when I use the code below and
the user presses ok the report runs and on close the form is restored. But if
the user presses the cancel button the form stays maximized because for some
reason the restore command doesn’t occur.
Maximizing which form? Are you referring to code in the command button that
opens the report? You could try Cancel = True rather than DoCmd.CancelEvent,
but I doubt it will make a difference?
Thank you for your input. To get it to work on the report open I used this.
[quoted text clipped - 19 lines]
 
B

BruceM via AccessMonster.com

Try restoring (Me.Restore) in the Activate event of the form. Restoring in
the Close event of the report applies Restore to that report, not to any
other object. I'm not sure why it works as you would like in one instance
but not the other, but I do think the code needs to be in the form's Activate
event.
I have a form that is built as a switchboard. When I press a command it
follows the handle number then opens a report. On the report properties I
have event procedures on the "On Open" and "On Close". the on open I tell it
to maximize and on the on close I tell it to restore. I have the form not
maximized in the access database but when you maximize a report it maximizes
the form unless you tell it to restore on close. then it puts the form window
back to the size you have previously set. So when I use the code below and
the user presses ok the report runs and on close the form is restored. But if
the user presses the cancel button the form stays maximized because for some
reason the restore command doesn’t occur.
Maximizing which form? Are you referring to code in the command button that
opens the report? You could try Cancel = True rather than DoCmd.CancelEvent,
[quoted text clipped - 5 lines]
 
J

Jesse via AccessMonster.com

I placed the me.restore in the activate event and it gave me an error of
"Application-defined or abject-defined error". After I typed the . it didnt
show restore in the list of objects that i could use. So it doesnt work in
the activate event. Im not sure why it works in one instance but not the
other either. Access can be strange sometimes.
Try restoring (Me.Restore) in the Activate event of the form. Restoring in
the Close event of the report applies Restore to that report, not to any
other object. I'm not sure why it works as you would like in one instance
but not the other, but I do think the code needs to be in the form's Activate
event.
I have a form that is built as a switchboard. When I press a command it
follows the handle number then opens a report. On the report properties I
[quoted text clipped - 12 lines]
 
B

BruceM via AccessMonster.com

Oops. Try DoCmd.Restore. Sorry about that. I used the syntax for Requery
and Refresh, but Restore is applied differently.
I placed the me.restore in the activate event and it gave me an error of
"Application-defined or abject-defined error". After I typed the . it didnt
show restore in the list of objects that i could use. So it doesnt work in
the activate event. Im not sure why it works in one instance but not the
other either. Access can be strange sometimes.
Try restoring (Me.Restore) in the Activate event of the form. Restoring in
the Close event of the report applies Restore to that report, not to any
[quoted text clipped - 7 lines]
 
J

Jesse via AccessMonster.com

That worked perfectly Bruce. Thank you for your help and for your time.
Oops. Try DoCmd.Restore. Sorry about that. I used the syntax for Requery
and Refresh, but Restore is applied differently.
I placed the me.restore in the activate event and it gave me an error of
"Application-defined or abject-defined error". After I typed the . it didnt
[quoted text clipped - 7 lines]
 

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