undo required field if fails validation

  • Thread starter Thread starter Francis
  • Start date Start date
F

Francis

hello i have 2 date fields and i want one to undo if its earlier the
the first using datediff, but the problem is i cant undo the value,
since when value is updated the focus moves away, and i was trying to
avoid using sendkeys "{ESC}"... what can i do in this case?

Private Sub txtDataVencimento_BeforeUpdate(Cancel As Integer)
Dim dd
dd = DateDiff("d", Me.txtDataEmissao, Me.txtDataVencimento)
If dd < 0 Then
Screen.PreviousControl.Value = Screen.PreviousControl.OldValue
MsgBox "Error: DataVencimento inferior then DataEmissão",
vbCritical
End If
End Sub

have also tryed some other ways but this one seemed the more logical
 
try replacing
Screen.PreviousControl.Value = Screen.PreviousControl.OldValue
with
Me![ContolName] = Me![ControlName].OldValue
 
Back
Top