Results 1 to 4 of 4
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    69

    Adding time values

    Good day all,
    I have a simple question today that I seem not be able to solve (maybe I need a break).
    I have 2 time columns per day, i.e 10 in total.
    At the end of the week, I want to add all the elapsed time for each day together in a seperate textbox.

    Calculating the elapsed time per day is easy. My issue is to add each days elapsed time together in the textbox. To calculate the time elapsed, I am using a short piece of code found on the internet:



    Code:
    Public Function ElapsedTime(endTime As Date, startTime As Date)    
        Dim Interval As Date
        
        ' Calculate the time interval.
        Interval = endTime - startTime
            
        ' Format and print the time interval in hours, minutes and seconds.
        strOutput = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn")
        
    End Function
    When the function returns the "strOutput" value, I want to add this to the current value of the tectbox:

    Code:
    Private Sub Command52_Click()Call ElapsedTime(TimeEnd1, TimeStart1)
    Me!Tot_Normal1.Value = Me!Tot_Normal1.Value + strOutput
    End Sub
    Running the latter produces an error.

    Any suggestions?

    Thanks
    Deon

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    When you call a function, you should set the return value to the function name, so no idea what that is doing?

    Code:
    ElapsedTime = Interval
    Calling it
    Code:
    ET = ElapsedTime(OneDate. SecondDate)
    You have not Dimmed StrOuput, so that tells me you do not have Option Explicit in the module? Even if you had it is local to that function.
    You do not even say what the error is? :

    DO NOT format the time until you want to display it, as that makes it a string and you cannot carry out math with strings.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Why are using a function to calculate the daily total. Why not just use an expression e.g. endTime - startTime and then also use an expression in the WeekTotal textbox e.g. Tot1+Tot2+Tot3+Tot4+Tot5
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    69
    Hi. I said maybe I need a break, and that is what I did.
    The calculation works fine now!!

    Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 05-04-2022, 02:42 PM
  2. Adding up time
    By chr1stoper1 in forum Queries
    Replies: 6
    Last Post: 03-06-2019, 07:06 PM
  3. Replies: 12
    Last Post: 07-19-2015, 05:21 PM
  4. Adding Time Values
    By tennisbuck in forum Access
    Replies: 3
    Last Post: 10-07-2014, 07:26 PM
  5. Adding Time help
    By Bozilla in forum Forms
    Replies: 3
    Last Post: 11-08-2011, 09:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums