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
 
No need for code unless you want additional messages. Just set Validation
Rule and Validation Text.

Open the form in design view and then click on menu VIEW - Properties.
Click on the textbox and enter in the Validation line this --
<[YourOtherTextFieldName]

In the Validtion Text enter something like --
This date must be earlier than that in xxxx. "xxxx" is the label you
give to the other date field on the form.
 
Back
Top