1-
Function DateCompare
trully needs a
As Boolean
somewhere
2- As SA stated, your logic in DateCompare is over-complicated.
I would use the
Validating
event of the DateTimePicker :
Private Sub DateTimePicker_Validating(ByVal sender As Object, ByVal e As CancelEventArgs) Handles dtpIn.Validating, dtpOut.Validating
If (dtpIn.Value > dtpOut.Value)
If (DirectCast(sender, DateTimePicker).Name = "dtpIn")
MsgBox("Date In Cannot be after Date Out, Please Amend.")
Else
MsgBox("Date Out Cannot be before Date In, Please Amend.")
End If
e.Cancel = True
End If
End Sub
Setting the
Cancel
property of the event to true will make that the user won't be able to leave the control without entering a valid date.