Hi joeu2004
Thanks for the feedback. I realize the format issues (like you explained). I was hoping to do the formatting via VBA, and not in the sheet. I want users to stay away from the sheet and the data. Safeguard it as much as possible.
This is the actual code I am using to format the time field to save it to the sheet in this format HH:MM
'TIME FORMAT
Private Sub txtWorkShiftStart_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim tString As String
If Me.txtWorkShiftStart = "" Then
MsgBox "Please enter a Work Start of Shift"
Cancel = True
End If
With txtWorkShiftStart
' don't process if blank
If Len(.Value) <> 0 Then
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tString = Left(tString, 2) & ":" & Right(tString, 2)
If IsDate(tString) Then
txtWorkShiftStart.Value = Format(TimeValue(tString), "HH:MM")
Else
MsgBox "Not a valid time value"
Cancel = True
End If
Else
If IsDate(.Value) Then
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm")
Else
MsgBox "Not a valid time value"
Cancel = True
End If
End If
End If
End With
End Sub
Perhaps any suggestions on how I can edit this to save in my desired format, but as numeric time?
Thank you!
Bookmarks