Me.FieldName.Undo not reverting back to previous value

C

CES

All,
I can't seem to get undo to work properly. If I'm right the correct syntax for undoing any change in the current field is:

Private Sub Category_BeforeUpdate(Cancel As Integer)
Me.Category.Undo
MsgBox (Me.Category.Value) ' Is returning the new value not the original value
End Sub


However, when I try to use this code, it has no effect on the record. The control is a combo box and the name of the control is "Category". If the Me.Category.value = 1 and I change the value to 2 via the combo box when I leave the field and go to the next field in my form the value in Me.Category.Value should revert back to 1.

I was also wondering if there was a way of getting the name of the current control In Focus... by that I mean, in this current case Me.???? What equal "Category". Thanks in advance. - CES
 
M

Marshall Barton

CES said:
I can't seem to get undo to work properly. If I'm right the correct syntax for undoing any change in the current field is:

Private Sub Category_BeforeUpdate(Cancel As Integer)
Me.Category.Undo
MsgBox (Me.Category.Value) ' Is returning the new value not the original value
End Sub


However, when I try to use this code, it has no effect on the record. The control is a combo box and the name of the control is "Category". If the Me.Category.value = 1 and I change the value to 2 via the combo box when I leave the field and go to the next field in my form the value in Me.Category.Value should revert back to 1.

I was also wondering if there was a way of getting the name of the current control In Focus... by that I mean, in this current case Me.???? What equal "Category". Thanks in advance. - CES


The key to this is that you need to cancel the update. Add
the line:
Cancel = True
to the procedure.

The BeforeUpdate event tentatively has the new Value but
after you leave the sub, it should revert to the old value.
 

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