Undo a change in a userform

G

Guest

Hello folks!

Is it possible undo a change from a combo box into a userform? For instance,
if someone selects "A" in the list, the user must answer to a question to
valid that he or she really wants to cancel. If the user hits No, I would
like the program to bring back the value that was showing just before.

Thanks,
gmore
 
M

merjet

Your post could have been much clearer, but I guessed that you may
want something like this.

Private Sub ComboBox1_Change()
Static aPrev As String
iRtn = MsgBox("Are you sure?", vbYesNoCancel)
If iRtn = 7 Then
ComboBox1.Value = aPrev
End If
aPrev = ComboBox1.Value
End Sub

Hth,
Merjet
 
G

Guest

You can keep track of the current selection by placing it in a user form
variable. Something like this in your form code module would work:

Private iCurrentIndex As Integer
Private Sub ComboBox1_Change()
If ComboBox1.ListIndex <> iCurrentIndex Then
If vbNo = MsgBox("Are you sure about this change?", vbYesNo) Then
ComboBox1.ListIndex = iCurrentIndex 'put the old selection back
End If
End If
End Sub

Private Sub ComboBox1_Enter()
iCurrentIndex = ComboBox1.ListIndex 'remember the current selection
End Sub
 
G

Guest

Thanks! It works fine.

Vergel Adriano said:
You can keep track of the current selection by placing it in a user form
variable. Something like this in your form code module would work:

Private iCurrentIndex As Integer
Private Sub ComboBox1_Change()
If ComboBox1.ListIndex <> iCurrentIndex Then
If vbNo = MsgBox("Are you sure about this change?", vbYesNo) Then
ComboBox1.ListIndex = iCurrentIndex 'put the old selection back
End If
End If
End Sub

Private Sub ComboBox1_Enter()
iCurrentIndex = ComboBox1.ListIndex 'remember the current selection
End Sub
 

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