• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Formating Text box to Time and having [Solved]

Status
Not open for further replies.

Dale Brown

New Member
Code:
Private Sub Txt_Date_Afterupdate()
Dim tString As String
With Txt_Date
  '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)

  Txt_Date.Value = Format(TimeValue(tString), "HH:MM") ' this line comes up as error 'type mismatch
  Else
  'Otherwise, take value as given
  .Value = Format(.Value, "hh:mm")
  End If
End With
End Sub

All fixed. Had wrong TxtBox Name
 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top