Hi,
I used a before Update procedure to check if the date of a textbox is later than another text box. However, nothing seem to happen when I enter the wrong date.
Here is my code:
Any help will be very much appreciated.
B
I used a before Update procedure to check if the date of a textbox is later than another text box. However, nothing seem to happen when I enter the wrong date.
Here is my code:
Code:
Private Sub txtDateOfCompletionForHandover_BeforeUpdate(Cancel As Integer)
Dim anticipatedCompletionDate As Date
Dim dateCompletionHandover As Date
'assign vars values
anticipatedCompletionDate = txtAnticipatedCompletionDate.Value
dateCompletionHandover = txtDateOfCompletionForHandover.Value
'If date1 refers to a later point in time than date2, the DateDiff function returns a negative number
If DateDiff("d", anticipatedCompletionDate, dateCompletionHandover) < 0 Then
MsgBox "You are trying to Handover house before the house is finished!" & vbCrLf & vbLf & _
"Please enter a later date than Anicipated Completion Date above.", , "House Handover"
'empty textbox and keep focus
txtDateOfCompletionForHandover.Text = ""
txtDateOfCompletionForHandover.SetFocus
End If
End Sub
Any help will be very much appreciated.
B