Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,665
- Office Version
- 365
- 2016
- Platform
- Windows
I am using this code to verify times being entered by users on a userform. users are entering start and end times of 8 hour shifts.
This works, however, if a user wishes to ender an 8 hour shift starting at 4:00 PM, the end time would be 12:00AM. But this code identifies this as an error ... "End time must be greater than the start time."
Can anyone suggest a way to overcome this? Yes, 12:00A does fall before 4:00PM, but not 12:00A the next day.
Code:
Sub CheckEntry2(aTextBox As MSForms.TextBox, ByVal CANCEL As MSForms.ReturnBoolean, ByVal dc2 As String)
Dim crew1 As String
Dim t As Date
With aTextBox
If IsDate(.Text) Then
t = TimeValue(.Text)
If Not (t >= dc2) Then
CANCEL = True
.SelStart = 0
.SelLength = Len(.Text)
MsgBox "End time must be greater than the shift start time." & vbLf & _
"Please re-enter a time greater than " & Format(dc2, "h:mm AM/PM"), _
vbExclamation, "INVALID ENTRY"
.Value = DateAdd("H", 8, dc2)
Exit Sub
End If
Else
CANCEL = True
.SelStart = 0
.SelLength = Len(.Text)
MsgBox "Invalid time entry. ", vbExclamation, "INVALID ENTRY"
.Value = ""
End If
.Text = Format(.Value, "h:mm AM/PM")
End With
gflag = 1
'If IsBadEntry Then Cancel = True
End Sub
This works, however, if a user wishes to ender an 8 hour shift starting at 4:00 PM, the end time would be 12:00AM. But this code identifies this as an error ... "End time must be greater than the start time."
Can anyone suggest a way to overcome this? Yes, 12:00A does fall before 4:00PM, but not 12:00A the next day.