cancel combo box change if option changed by mistake

C

ChrisP

I have a combo box with a number of options. I am trying to prevent the
combo box from saving a change if they should inadvertingly select the job
as completed. I want a messag box to pop up to remind them of what they have
done and if they select "No" to have the combo box retain the old value.
Can't seem to work out how to make this work. I have tried using undo and
believe I should be able to use the cancel event in the beforeupdate event
as follows but doesn't seem to work.
Hope someone can suggest a way of doing this.
Thanks
Chris

Private Sub ComboStatus_BeforeUpdate(Cancel As Integer)
Dim intYN As Integer
Select Case Me.ComboStatus

Case "Completed"

intYN = MsgBox("Do you want to set this company to Completed",
vbInformation + vbYesNo)

If intYN = vbYes Then
Completed_Update
Else
Cancel = True 'if no selected cancel event and reset combo box field to
old value.
Exit Sub
End If

'others cases will follow........................

End Select

End Sub
 
A

Arni Laugdal

Dear Chris,
Following Sub will do the job:

Private Sub ComboStatus_BeforeUpdate(Cancel As Integer)
If MsgBox("Do you want to set this company to
Completed", vbInformation + vbYesNo) = vbNo Then
Cancel = True
SendKeys "{Esc}"
End If
End Sub

Enjoy!
Arni Laugdal, MMI
 

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