We help IT Professionals succeed at work.

vbYes or No, cancel if No

Experts, how can I undo what was selected if user selects NO?   I was assuming that in a vbYesNo if user  selects No then it wont change the value of the combo box but it changes it independent of whether user selects Yes or No.  

thank you

(I might also need to account for whether or not the record is new but maybe by saying Not is Null then that handles it)

Private Sub cboLCType_BeforeUpdate(Cancel As Integer)

        If Not IsNull(Me!cboLCType) Then
            MsgBox "Are you sure you want to change the LC Type?", vbYesNoCancel

        End If
End Sub
Comment
Watch Question

Author

Commented:
I also tried afterupdate and same results...
Most Valuable Expert 2012
Top Expert 2013

Commented:
Try this:

Private Sub cboLCType_BeforeUpdate(Cancel As Integer)

        If Not IsNull(Me!cboLCType) Then
             if  (MsgBox "Are you sure you want to change the LC Type?", vbYesNoCancel) <> vbyes then
             me.cboLCType.undo
             Cancel = true
            end if

        End If
End Sub 

Open in new window

Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
The message box presents a user prompt and returns a value, nothing more.  You have to tell your abblication what to do based on the return value.

Author

Commented:
mbizup:  I have a syntax (or at least it is red when go to another line) on the
if  (MsgBox "Are you sure you want to change the LC Type?", vbYesNoCancel) <> vbyes then


Most Valuable Expert 2012
Top Expert 2013
Commented:
Sorry - I got the parentheses in the wrong place:

Private Sub cboLCType_BeforeUpdate(Cancel As Integer)

        If Not IsNull(Me!cboLCType) Then
             if  MsgBox ("Are you sure you want to change the LC Type?", vbYesNoCancel) <> vbyes then
             me.cboLCType.undo
             Cancel = true
            end if

        End If
End Sub  

Open in new window

Most Valuable Expert 2012
Top Expert 2013

Commented:
<< vbYes or No, cancel if No>>

Just a note - the syntax I'm using assumes that you want the user to explicitly confirm with a YES.

Everything else (no, cancel, or simply closing the dialog box) will cancel the update.

Author

Commented:
that was exactly what I was after. thank you.
Most Valuable Expert 2012
Top Expert 2013

Commented:
Glad to help out :-)