Results 1 to 5 of 5
  1. #1
    Al77 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    20

    Simple elapsed time expression giving #error

    Hi folks!

    I have two fields in a table for entering elapsed time in the format hh:nn:ss or nn:ss, depending on whether there are any hours (rare).

    When I create a SIMPLE expression to convert the above entries into decimal MINUTES, only the hh:nn:ss version works, the other returning an #Error message.

    This has completely thrown me because it seems so simple and I have not fiddled with any other settings (as far as I know).

    Expression = Minute([TimeN(ms)]), which is virtually IDENTICAL to the other version = Minute([TimeN(hms)]) that actually works !

    Alternatively, is there any way of creating a field that allows quick / clean entry of time in EITHER format? i.e. WITHOUT leading zeros when there are no hours, essentially pushing the first four entries to the last four places when there are no hours to be recorded (if that makes sense) - i.e. when 1250 is entered, it shows as 00:12:50.

    Any ideas?



    Thanks

    Al

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Are these date/time type fields?

    Need all 3 time parts for calculation.

    One field to allow either input? Not without VBA.

    Could input into 3 fields then in code concatenate for calculations.

    Minute() function only pulls the minutes part, ignores the hours and seconds. Is that what you really want?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
    Function ElapsedTime(endTime As Date, startTime As Date)
        Dim strOutput As String
        Dim Interval As Date
    
    
        ' Calculate the time interval.
        Interval = endTime - startTime
    
    
        ' Format and print the time interval in seconds.
        strOutput = Int(CSng(Interval * 24 * 3600)) & " Seconds"
        Debug.Print strOutput
    
    
        ' Format and print the time interval in minutes and seconds.
        strOutput = Int(CSng(Interval * 24 * 60)) & ":" & Format(Interval, "ss") _
                  & " Minutes:Seconds"
        Debug.Print strOutput
    
    
        ' Format and print the time interval in hours, minutes and seconds.
        strOutput = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn:ss") _
                  & " Hours:Minutes:Seconds"
        Debug.Print strOutput
    
    
        ' Format and print the time interval in days, hours, minutes and seconds.
        strOutput = Int(CSng(Interval)) & " days " & Format(Interval, "hh") _
                  & " Hours " & Format(Interval, "nn") & " Minutes " & _
                    Format(Interval, "ss") & " Seconds"
        Debug.Print strOutput
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    Al77 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    20
    Basically, I created a two or three part expression to extract all minutes = 1. Hours*60 + Minutes + Seconds/60, or 2. just Minutes + Seconds/60.

    Data entered as hh:nn:ss or nn:ss, as menioned.

    Maybe i am going about this the wrong way around and you know a quicker way / expression?

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    this function should do what you want

    Code:
    Function ElapsedTime(endTime As Date, startTime As Date) As String
        Dim strOutput As String
        Dim Interval As Date
    
    
        Interval = endTime - startTime
    
    
        If Int(Format(Interval, "hh")) <> 0 Then
            strOutput = strOutput & (Format(Interval, "hh")) & ":"
        Else
            'strOutput = strOutput & "00:"  'uncomment if you want to include 00: value for no hours
        End If
    
    
        If Int(Format(Interval, "nn")) <> 0 Then
            strOutput = strOutput & (Format(Interval, "nn")) & ":"
        Else
            strOutput = strOutput & "00:"
        End If
    
    
        If Format(Interval, "ss") <> 0 Then
            strOutput = strOutput & Format(Interval, "ss")   
        Else
            strOutput = strOutput & "00"
        End If
    
    
        ElapsedTime2 = strOutput
    
    
    End Function
    results will look like
    Code:
    01:02:27
    02:27
    personally I think it may be confusing to have 2 different formats
    If you un-comment the commented line, if theres no hours it will output
    Code:
    00:02:27
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 5
    Last Post: 08-17-2020, 08:43 PM
  2. Replies: 3
    Last Post: 03-14-2016, 05:10 AM
  3. Control source Expression giving #Error
    By N3w2access in forum Forms
    Replies: 5
    Last Post: 01-21-2014, 07:53 AM
  4. fuction elapsed time, expression builder
    By zac123 in forum Access
    Replies: 1
    Last Post: 08-05-2011, 02:21 PM
  5. Replies: 2
    Last Post: 05-17-2011, 02:40 PM

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