I have a Down Time table with a BeginTime field and an EndTime field. These fields are separate from the BeginDate field and EndDate field and are formatted as Date/Time fields. When entering the down Time on a form I want to ensure that the EndTime entered is later than the BeginTime. MWhen the "Save" button is clicked, I perform a check to make sure BeginTime is greater than EndTime as shown below:
Select Case Me.txtEndTime
Case (IsNull(TimeValue(Me.txtEndTime)) Or (TimeValue(Me.txtEndTime) = #12:00:00 AM#))
myMsg = MsgBox("You must enter a valid End Time.", vbInformation, "Invalid End time")
Cancel = True
DoCmd.GoToControl "txtEndTime"
' Case (TimeValue(Me.txtEndTime) < TimeValue(Me.txtBeginTime))
Case (StrComp(Me.txtEndTime, Me.txtBeginTime) = -1)
myMsg = MsgBox("End Time must be greater than Begin Time", vbInformation, "Invalid End time")
Cancel = True
DoCmd.GoToControl "txtEndTime"
Case (Me.txtEndTime < Me.txtBeginTime) And (DateValue(Me.txtEndDate) <= DateValue(Me.txtBeginDate))
myMsg = MsgBox("End Time must be greater than Begin Time", vbInformation, "Invalid End time")
Cancel = True
DoCmd.GoToControl "txtEndTime"
End Select
When I debug the code it just falls through even though I enter an End time that is less than the begin time. In the immediate window the StrComp function returns 1 in stead of -1. The first Case is Ok when I don't enter an EndTime or skip the txtEndTime control that has a time of 0:00. the Third Case doesn't catch an invalid EndTime either.
What am I doing wrong? Please help.
Thank you.