終了日と表示メッセージの後かどうかを確認するための開始日を既に取得していますが、次のコードを配置すると.focusコードが2回実行されるようです。新しいスレッドに、機能せず、関数にも機能しませんでした
ここにコードがあります
Function DateCompare(ByVal Start As Date, ByVal Finish As Date, ByVal WhichDate As String)
If WhichDate = "DateIn" Then
If DateTime.Compare(Start, Finish) > 0 Then
MsgBox("Dates Are Invalid : Date In Cannot be after Date Out, Please Amend", vbExclamation, "Dates Are Incorrect")
Return False
Exit Function
Else
Return True
End If
Else
If DateTime.Compare(Finish, Start) < 0 Then
MsgBox("Dates Are Invalid : Date Out Cannot be before Date In, Please Amend", vbExclamation, "Dates Are Incorrect")
Return False
Exit Function
Else
Return True
End If
End If
End Function
Private Sub dtpDateTimeIn_leave(ByVal sender As Object, ByVal e As EventArgs) Handles dtpDateTimeIn.Leave
Dim result As Boolean
result = DateCompare(dtpDateTimeIn.Value, dtpDateTimeOut.Value, "DateIn")
If result = False Then
dtpDateTimeIn.Focus()
End If
End Sub
Private Sub dtpDateTimeOut_leave(ByVal sender As Object, ByVal e As EventArgs) Handles dtpDateTimeOut.Leave
Dim result As Boolean
result = DateCompare(dtpDateTimeIn.Value, dtpDateTimeOut.Value, "DateOut")
If result = False Then
dtpDateTimeOut.Focus()
End If
End Sub