On Change VB Yes/No Question and Undo!

D

Dave Elliott

I have a combo box the looks up the contractor, name, address, phone, fax...
If the user changes the value of this i want a message box to popup and say
are you sure, change contractor?
Also if they say yes, then save, else if no then undo the change.
How can I do this?

Thank You So Much

Dave
 
A

Allen Browne

Use the AfterUpdate event procedure of the combo to ask for confirmation:

Private Sub Contractor_AfterUpdate()
If MsgBox("Change?", vbYesNo+vbDefaultButton2) = vbNo Then
Me.Contractor.Undo
End If
End Sub
 
J

John Vinson

I have a combo box the looks up the contractor, name, address, phone, fax...
If the user changes the value of this i want a message box to popup and say
are you sure, change contractor?
Also if they say yes, then save, else if no then undo the change.
How can I do this?

Thank You So Much

Dave

I'd use the BeforeUpdate event (which can be cancelled):

Private Sub cboContractor_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
iAns = MsgBox("Are you SURE you want to change contractors?", vbYesNo)
Cancel = (iAns = vbNo)
End Sub

John W. Vinson[MVP]
 
Top