Undo

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks for taking the time to read my question.

I have combo boxes that if the value selected is the same as another combo
box, displays a message saying so, and SHOULD undo the change and make the
user select another value.

My code isn't working.

CantChoose is a function that sets CantChooseVal to True if criteria met. I
have stepped through the code and it enters the if, but the value of the
combo box doesn't change back.

I don't know why.

Please help,

Brad

Code:

Private Sub SplitCategory1_BeforeUpdate(Cancel As Integer)
CantChooseVal = False
CantChoose (1)
If CantChooseVal = True Then
MsgBox "This Category has been chosen on another record. Please select
another category, or change the category of the record that has the same
value.", 16
Me.SplitCategory1.Undo
'Cancel = True
End If
End Sub
 
try putting it in the control's OnExit event procedure instead, as

Private Sub SplitCategory1_Exit(Cancel As Integer)

CantChooseVal = False
CantChoose (1)

If CantChooseVal Then
Cancel = True
Me!SplitCategory1= Null
End If

End Sub

hth
 
If I do that, the record gets updated, and the user looses what they had in
the combo box before.

It's a good idea though.

thanks,

Brad
 
the value in the control will be changed to Null, but the record data does
not get written to the table until you 1) move to another record, 2) save
the record from the toolbar/menu bar option/VBA, or 3) close the form.
if you want to monitor the comparative value of the combo boxes before the
record is updated, and take action conditionally, usually the best place to
do that is in the form's BeforeUpdate event.

hth
 
Back
Top