Results 1 to 9 of 9

Thread: [RESOLVED] using hh:mm:ss counting format in Access

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Resolved [RESOLVED] using hh:mm:ss counting format in Access

    i have an excel spreadsheet that has time in format:

    hh:mm:ss

    not in the sense of a time, in the sense of an incremental counter.

    when i import to access, it does not recognise this format and instead formats as text.
    if you change to time it changes it to am, pm time and removes any count that is greater than an expected time.

    any way to get this to work in access? the spreadsheet is getting a bit big and cumbersome.

    TIA
    Last edited by Br1an_g; May 4th, 2005 at 01:17 PM. Reason: resolved
    if you fail to plan, you plan to fail

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: using hh:mm:ss counting format in Access

    You probably need to define your access field as Date/Time with a custom Format as hh:nn:ss.
    I did that and typed in 17:24:59 and it stayed. Now if your timer time is from 00 to 59, etc. you should be good to go.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: using hh:mm:ss counting format in Access

    yeh, i tried that.

    if you type in 25:25:25

    it wont accept because it is outwith the 24 hour clock, but as a timer it needs to be able to do this..

    anything else i can do? can i use a function to convert it from text to a timer? or take the 24hours away, then use the remainder to calculate?

    e.g. 25:25:25, i take away the 24 hours to make 1 day, 1 hour 25min 25 secs.

    the prob ive encountered is that it wont let me use any functions on a time over 24 hours..

    help
    if you fail to plan, you plan to fail

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: using hh:mm:ss counting format in Access

    Ok, its over 23 and 59 so I think the best solution is to store it as text in your format. Then you need to convert it
    to time after reading it from the db and before populating the cell in Excel.

    Using the Mod function is the way to go. I'll post an example in a minute.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: using hh:mm:ss counting format in Access

    Will the time ever be beyond 99:99:99?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: using hh:mm:ss counting format in Access

    Well, I just made a guess and assumed that it will. So here is a sloppy example. I'm sure you knew what I meant by
    using Mod but I just wanted to complete the post.

    VB Code:
    1. Dim sTest As String
    2.     Dim sDays As String
    3.     Dim sHours As String
    4.     Dim sMinutes As String
    5.     Dim sSeconds As String
    6.     Dim iStart As Integer
    7.     Dim iEnd As Integer
    8.    
    9.     sTest = "25:83:98"
    10.     iStart = InStr(1, sTest, ":")
    11.     iEnd = InStr(iStart + 1, sTest, ":")
    12.     sHours = Left$(sTest, InStr(1, sTest, ":") - 1)
    13.     sMinutes = Mid$(sTest, InStr(iStart, sTest, ":") + 1, (iEnd - iStart) - 1)
    14.     sSeconds = Mid$(sTest, InStr(iEnd, sTest, ":") + 1, Len(sTest) - iEnd)
    15.     If CInt(sSeconds) > 59 Then
    16.         sSeconds = sSeconds - 60
    17.         sMinutes = sMinutes + 60
    18.     End If
    19.     If CInt(sMinutes) > 59 Then
    20.         sHours = (sHours + ((sMinutes) / 60)) Mod 60
    21.         sMinutes = sMinutes Mod 60
    22.     End If
    23.     If CInt(sHours) > 24 Then
    24.         sDays = (sHours / 24) Mod 24
    25.         sHours = (sHours - 24) Mod 24
    26.     End If
    27.     MsgBox sDays & " Day(s) " & sHours & ":" & sMinutes & ":" & sSeconds '1 Day(s) 3 Hours 23 minutes and 38 seconds
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: using hh:mm:ss counting format in Access

    Just a thought:
    Could you use API GetTickCount or similar as the number counting up?
    Or use cdbl on the Now function to get a number?

    The Now converted to a number can always be converted back to a date/time later on (including days)

    The API GetTick is only an option, and probably wouldn't be useful as I think it runs from when the comp is turned on, but you may want to read up on it anyway?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: using hh:mm:ss counting format in Access

    thanks for all of the suggestions.
    ended up it was simpler than i thought.

    access does actually increment above the 24hours, but it adds days to a date, so to get the actual hours i wanted i divided it by 24, put this into another text box overlapping the actual time it was showing as the minutes and seconds were always correct.

    VB Code:
    1. DatePart("h",Sum([TimeField]))/24

    there were a couple of variations needed on the form to ensure it was correct, but that is the main part of it.

    Thanks again
    if you fail to plan, you plan to fail

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESOLVED] using hh:mm:ss counting format in Access

    If CInt(sSeconds) > 59 Then
    sSeconds = sSeconds - 60
    sMinutes = sMinutes + 60
    End If
    Shouldn't that be:

    VB Code:
    1. If CInt(sSeconds) > 59 Then
    2.         sSeconds = sSeconds - 60
    3.         sMinutes = sMinutes [B]+ 1
    4. [/B]    End If

Posting Permissions

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



Click Here to Expand Forum to Full Width