Command button help

Posted on 2012-08-22
Last Modified: 2012-08-23
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
Question by:Kiwi-123
    LVL 18

    Expert Comment

    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.
    LVL 18

    Accepted Solution


    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now