Results 1 to 6 of 6
  1. #1
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105

    how to deal with null time value in text box

    I have a query that retrieves an employees schedule for the week. There is a field for start time and a field for finish time. I then place those values in text boxes on a schedule form. Sunday through Saturday.

    Long story short, I would like to subtract the finish time from the start time and then format it.


    Example;
    Start = 8:15AM
    Finish = 5:32PM
    Total Hours Worked (formatted to look like this): 9h 17m

    I have this working right now. The problem is, when the text boxes are empty, it throws an exception. I have it working fine until it reaches a day with no entry. For instance, If Sunday and Monday both have start and finish time entrys in their respective text boxes, the label below it holding the hours worked is good. But then Tuesday the employee is off, and it throws an invalid type error. Wednesday, etc., there are entries, but it doesn't go any further.

    Any ideas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Show the query and the expression for the calculation.

    Maybe using Nz function will take care of this.
    Nz(starttime,0)
    Nz(finishtime,0)
    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
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    Here's my code that works. The problem is when I hit the button that calls the function, I get a "Type Mismatch" error if all 7 days aren't filled in with start times and end times, and it stops on the first null day.

    To explain the code, basically if there is no quit time (employee may still be clocked in), then display "0h 0m" in the hours worked label. Otherwise, subtract the quit time from the start time (produces a time value, like 8:15AM) and then format the hours and minutes section of it. I can't figure out why its not just skipping the null days.

    Code:
        Dim hrsW As Date
        If IsNull(Me.txtSunAcQuit.Value) Then
            Me.lblSunHrs.Caption = "0h 0m"
        Else
            hrsW = Me.txtSunAcStart.Value - Me.txtSunAcQuit.Value
            Me.lblSunHrs.Caption = Format(hrsW, "h") & "h " & Format(hrsW, "n") & "m"
        End If

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    So test first:

    Code:
    If IsDate(...) And IsDate(...) Then
      'do your thing
    Else
      'they're not filled out
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RedGoneWILD is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2010
    Posts
    105
    that worked thanks baldy

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 21
    Last Post: 05-20-2012, 02:15 PM
  2. Null alternative for Date/Time field
    By tylerg11 in forum Forms
    Replies: 1
    Last Post: 04-11-2012, 04:04 PM
  3. having to deal with massive query's
    By quandore in forum Access
    Replies: 1
    Last Post: 01-11-2012, 08:34 AM
  4. Replies: 12
    Last Post: 12-11-2011, 05:04 PM
  5. Replies: 1
    Last Post: 07-14-2008, 12:15 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