Consulting

Results 1 to 5 of 5

Thread: vba adding up time with spin control & text box with userfirendly output

  1. #1
    VBAX Regular
    Joined
    Nov 2019
    Posts
    10
    Location

    vba adding up time with spin control & text box with userfirendly output

    hi all,


    i have a useform textbox controlled by a spin button that a user will input time taken to complete a task, this works fine in increments of 15mins (0.25)

    however the output isnt very user friendly,

    me.txthours.value is then sent to a DB and a calculation (value*hourly rate) hence why its in 0.25 values.

    Private Sub sbTime_SpinUp()
    
    
    Me.txtHours.value = Me.txtHours.value + 0.25
    
    
    End Sub
    value output displayed Disired Display value
    0.25 15
    0.5 30
    0.75 45
    1 1
    1.25 1:15
    1.5 1:30
    1.75 1:45
    2 2
    2.25 2:15
    2.5 2:30
    2.75 2:45
    3 3


    any help with this would be greatly appreciated.

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    MsgBox Format(.25 / 24, "hh:mm")

  3. #3
    VBAX Regular
    Joined
    Nov 2019
    Posts
    10
    Location
    Quote Originally Posted by JKwan View Post
    MsgBox Format(.25 / 24, "hh:mm")
    can you please elaborate im struggling to get this to work

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    A TextBox can only contain, erm…, oh that's right, text.
    Private Sub sbTime_SpinUp()
    Me.txtHours.Value = Format(TimeValue(txtHours.Value) + TimeValue("00:15:00"), "hh:mm")
    End Sub
    The value in hours to the DB will be TimeValue(txtHours.Value) * 24

    Instead of + TimeValue("00:15:00") you could use + 1/96
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    ah, silly me.... did not think of that, p45cal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •