Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

Command button help

Please can you help with the attached.

I was hoping to do away with txtMins1 & txtMins2

Basically the two text boxes which contain the minutes.

I was hoping that I could add these to the txtHrs1 & txtHrs1 boxes.

Therefore when entering a time you would only need to type 1230 for 12:30

Currently you have to input 12 & then 30 for it to combine
1 Solution
RartemassAuthor, martial arts coach, IT ConsultantCommented:
First you will need to edit the form so the time is one field. I would delete the MM field and widen the hours.
Then delete all references to txtMins1 and txtMins2 in the code.
You will need to change the txtHrs1.MaxLength and txtHrs1.MaxLength to 4 instead of 2.

You will also need to modify the formulas and calculations so that it treats 1230 as a time rather than hours and minutes.

you could tr something like

Private Sub TextBox1_AfterUpdate()
    With Me.TextBox1
        If InStr(1, .Value, ":") = 0 Then
            .Value = Evaluate("text(" & .Value & ",""00\:00"")")
        End If
    End With
End Sub
'// Allow only numbers
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case KeyAscii
        Case 48 To 57
        Case Else: KeyAscii = 0
    End Select
End Sub

Open in new window


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now