ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Undo a change in a userform (https://www.excelbanter.com/excel-programming/384493-undo-change-userform.html)

gmore

Undo a change in a userform
 
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

merjet

Undo a change in a userform
 
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


Vergel Adriano

Undo a change in a userform
 
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



"gmore" wrote:

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


gmore

Undo a change in a userform
 
Thanks! It works fine.

"Vergel Adriano" wrote:

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



"gmore" wrote:

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



All times are GMT +1. The time now is 12:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com