Cancel Button not working

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)

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
Jesse
2/22/2010 10:24:16 PM
access.forms 6864 articles. 2 followers. Follow

16 Replies
1410 Views

Similar Articles

[PageSpeed] 49

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!

-- 
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

0
Linq
2/22/2010 10:32:36 PM
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.

Linq Adams wrote:
>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!
>

-- 
Message posted via http://www.accessmonster.com

0
Jesse
2/22/2010 10:46:17 PM
Actually, the posted code DOES include what buttons should appear. The ", 1" 
after the text corresponds to vbOkCancel.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Linq Adams via AccessMonster.com" <u28780@uwe> wrote in message 
news:a408923c31ce3@uwe...
> 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!
>
> -- 
> There's ALWAYS more than one way to skin a cat!
>
> Answers/posts based on Access 2000/2003
>
> Message posted via http://www.accessmonster.com
> 

0
Douglas
2/23/2010 2:27:39 AM
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

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Jesse via AccessMonster.com" <u50870@uwe> wrote in message 
news:a408b0b3f5930@uwe...
> 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.
>
> Linq Adams wrote:
>>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!
>>
>
> -- 
> Message posted via http://www.accessmonster.com
> 

0
Douglas
2/23/2010 2:29:26 AM
Sorry, Doug, I missed that! But, of course, the code did nothing depending on
which button was pressed!

-- 
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
Linq
2/23/2010 3:29:42 AM
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

Douglas J. Steele wrote:
>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!

-- 
Message posted via http://www.accessmonster.com

0
Jesse
2/23/2010 3:24:22 PM
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.

Jesse wrote:
>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]
>>> All
>>> you're doing is presenting a message!

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
Jesse
2/23/2010 3:30:52 PM
You would have needed Cancel = True in the code to cancel the report opening.


Jesse wrote:
>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]
>>>> All
>>>> you're doing is presenting a message!

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
BruceM
2/23/2010 4:38:46 PM
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.

Jesse wrote:
>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]
>>>> All
>>>> you're doing is presenting a message!

-- 
Message posted via http://www.accessmonster.com

0
BruceM
2/23/2010 4:41:17 PM
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

BruceM wrote:
>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]
>>>>> All
>>>>> you're doing is presenting a message!

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
Jesse
2/23/2010 5:04:28 PM
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?

Jesse wrote:
>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]
>>>>>> All
>>>>>> you're doing is presenting a message!

-- 
Message posted via http://www.accessmonster.com

0
BruceM
2/23/2010 5:45:30 PM
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.

BruceM wrote:
>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]
>>>>>>> All
>>>>>>> you're doing is presenting a message!

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
Jesse
2/23/2010 6:04:21 PM
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.

Jesse wrote:
>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]
>>>>>>>> All
>>>>>>>> you're doing is presenting a message!

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
BruceM
2/23/2010 7:23:05 PM
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.

BruceM wrote:
>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]
>>>>>>>>> All
>>>>>>>>> you're doing is presenting a message!

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
Jesse
2/23/2010 8:15:26 PM
Oops.  Try DoCmd.Restore.  Sorry about that.  I used the syntax for Requery
and Refresh, but Restore is applied differently.

Jesse wrote:
>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]
>>>>>>>>>> All
>>>>>>>>>> you're doing is presenting a message!

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201002/1

0
BruceM
2/24/2010 12:16:47 PM
That worked perfectly Bruce. Thank  you for your help and for your time.

BruceM wrote:
>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]
>>>>>>>>>>> All
>>>>>>>>>>> you're doing is presenting a message!

-- 
Message posted via http://www.accessmonster.com

0
Jesse
2/24/2010 3:19:42 PM
Reply:

Similar Artilces: