It would seem that an Undo would restore all the record's OldValues,
including the one in the textbox.
So the only problem would be to get the 3rd Party control updated with the
Old Value as well.
Correct. And without documentation for the control OldValue, I don't trust
it to have what I need. I'm guessing the control does not know why Value is
changed (it could be Form_Current, or it could be the user clicking on a
series of updates). So, I'm guessing OldValue is updated every time Value
is changed, which is not very helpful. What I need is the OldValue when
Form_Current fired, and not the values between then and Form_Undo. So, I
created my own variable myOldValue that is set in Form_Current, and
referenced in Form_Undo (which I think is really Form_BeforeUndo as best I
can tell, though it is named Undo).
The question then becomes -
what is invoking this Undo?
If it's an Undo button, it's easy to add code to update the 3rd Pary
Control.
That's what I did. It seems to work in simple cases, though this is my
first Access project, so I've probably overlooked something.
If it's being invoked by using the Esc key or some other shortcut, it
will be a little more work, but still quite doable.
I think it works with both Edit | Undo and Ctl-Z. When Form_Undo is called,
I just reset the control value to myOldValue. Here is my code thus far.
The control value counts days from 12/30/1899, so the conversion to Access
dates is a bit tedious to include support for Null dates, but that issue
aside, Form_Current copies the form value to the control value,
control_Update copies the control value to the form value, and Form_Undo
resets the control value back to the forms value at the Form_Current event.
Comments graciosly welcomed.
Dim myOldValue As Variant
Private Sub Form_Current()
' Copy the form value to the control value if they differ
If IsNull(Me.ScheduleDate) Then
If Me.ctDropDate9.Value <> 1 Then
Me.ctDropDate9.Value = 1
End If
ElseIf Me.ctDropDate9.Value <> DateDiff("d", "12/30/1899",
Me.ScheduleDate) Then
Me.ctDropDate9.Value = DateDiff("d", "12/30/1899", Me.ScheduleDate)
End If
' Save the value in the event of Form_Undo
myOldValue = Me.ctDropDate9.Value
End Sub
Private Sub Form_Undo(Cancel As Integer)
' Restore the control the the old value
Me.ctDropDate9.Value = myOldValue
End Sub
Private Sub ctDropDate9_Updated(Code As Integer)
' Copy the control value to the form value if they differ
If IsNull(Me.ScheduleDate) Then
If Me.ctDropDate9.Value <> 1 Then
Me.ScheduleDate = DateAdd("d", Me.ctDropDate9.Value,
"12/30/1899")
End If
Else
If Me.ctDropDate9.Value = 1 Then
Me.ScheduleDate = ""
Else
If Me.ctDropDate9.Value <> DateDiff("d", "12/30/1899",
Me.ScheduleDate) Then
Me.ScheduleDate = DateAdd("d", Me.ctDropDate9.Value,
"12/30/1899")
End If
End If
End If
End Sub