How do I get the YesNoCancel option to work?

Jonathanw

Board Regular
Joined
May 3, 2004
Messages
73
I have the following snippet of code, used in a database:

Private Sub Cancel_MAF_Click()
If Status.Value = "Incomplete" Then
MsgBox "This record can NOT be Canceled, please Delete this record!", vbInformation, "WARNING!"
DoCmd.RunCommand acCmdRefresh
ElseIf Status.Value = "Cancelled" Then
MsgBox "This record is already cancelled", vbInformation, "WARNING!"
Else

MsgBox "You are about to Cancel this record, are you REALLY sure you wish to do this? Re-Authorisation WILL be required if you do this in error", vbYesNoCancel
Status.Value = "Cancelled"
DoCmd.RunCommand acCmdRefresh
End If

End Sub

The problem here is, if you Click on either Yes, No, or Cancel the record is set to Cancelled. This is not really what I want. How do I get this to work?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Sorted this, I have been scouring web pages etc etc. and this is what I have done to get it to work.

If MsgBox("You are about to Cancel this record, are you REALLY sure you wish to do this? Re-Authorisation WILL be required if you do this in error", vbOKCancel) = vbCancel Then Exit Sub

Cheers
Jonathan W
 
Upvote 0
You need to get the result of the Msgbox.

eg.

ConfirmCancel = MsgBox ("You are about to Cancel this record, are you REALLY sure you wish to do this? Re-Authorisation WILL be required if you do this in error", vbYesNoCancel)

And then use it in an if statement:

If ConfirmCancel = vbYes Then

Status.Value = "Cancelled"
DoCmd.RunCommand acCmdRefresh

End If
 
Upvote 0

Forum statistics

Threads
1,221,798
Messages
6,162,027
Members
451,737
Latest member
MRASHLEY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top