Results 1 to 6 of 6
  1. #1
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234

    Shift time defaulting to 2 hours


    Not sure why, I can't find the answer by reading the code, but in the fee calculator (Shown here), if the hours worked (like #1) are less than 2 hours, it automatically rounds up to 2 hours.
    Click image for larger version. 

Name:	Feel calc.png 
Views:	16 
Size:	14.9 KB 
ID:	21474

    Now, there is a module called: basFeeCalcTotals_RoundUp, but after reading the entire thing, attached as a document, I can't find anything that tells it to round up.

    I'm also attaching as a document the code for the frmFeeCalculator. Can someone with more experienced eyes please read the code and tell me why it's rounding automatically up to 2 hours?

    Thank you!

    Codes.doc

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It is not in "basFeeCalcTotals_RoundUp", it is in "basPPAStaffingWorksheet".

    Here is the Sub name and the section of code (in blue):
    Code:
    Public Function calcLaborSubTotal()
        Dim db As Database
        Dim rst As Recordset
        Dim sql As String
        Dim ShiftStartDateTime As Date
        Dim ShiftEndDateTime As Date
        Dim ShiftEndDate As Date
        Dim ShiftLength As Single
        Dim SubTotal As Currency
        Dim strSubTotal As String
        Dim SubLaborTotal As Currency
        Dim strSubLaborTotal As String
        Dim SubGratTotal As Currency
        Dim strSubGratTotal As String
        Dim GratTotal As Currency
        Dim strGratTotal As String
        Dim length As Byte
        Dim LaborTotal As Currency
        Dim strLaborTotal As String
        Dim LaborTotalLength As Byte
        Dim GratTotalLength As Byte
        Dim lngEventID As Long
        Dim SubGratuityTotal As Currency
        Dim tblSubLaborTotal As Currency
        Dim lngPPAStaffingWorksheetID As Long
        
        
        
        ShiftStartDateTime = Format(Forms!frmEvent!txtEventDate, "Short Date") & " " & Forms!frmFeeCalculator!chldfsubPPAStaffingWorksheet!txtStartTime
        If Forms!frmFeeCalculator!chldfsubPPAStaffingWorksheet!txtStartTime > Forms!frmFeeCalculator!chldfsubPPAStaffingWorksheet!txtEndTime Then
            ShiftEndDate = Forms!frmEvent!txtEventDate + 1
            ShiftEndDateTime = ShiftEndDate & " " & Forms!frmFeeCalculator!chldfsubPPAStaffingWorksheet!txtEndTime
        Else
            ShiftEndDateTime = Format(Forms!frmEvent!txtEventDate, "Short Date") & " " & Forms!frmFeeCalculator!chldfsubPPAStaffingWorksheet!txtEndTime
        End If
        
        If (ShiftEndDateTime - ShiftStartDateTime) * 24 < 2 Then
            ShiftLength = 2
        Else
            ShiftLength = (ShiftEndDateTime - ShiftStartDateTime) * 24
        End If
    <snip>

  3. #3
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Sweet. I changed it by removing the "ShiftLength=2 Else" so now it just reads: If (ShiftEndDateTime - ShiftStartDateTime)*24 < 2 Then ShiftLength = (ShiftEndDateTime-ShiftStartDateTime) * 24.

    Thanks again!

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Have you thought through the logic???


    Answer me this: What is the value of "ShiftLength" if the shift length is greater than 2???
    I think "ShiftLength" will be zero/NULL........
    I would hate to work for you for more that 2 hours a day.



    You changed the code to this, but this calculates the shift length ONLY IF the length is less than 2 hrs!!!
    Code:
        If (ShiftEndDateTime - ShiftStartDateTime) * 24 < 2 Then  'this calculates the shift length ONLY IF the length is less than 2 hrs!!!
            ShiftLength = (ShiftEndDateTime - ShiftStartDateTime) * 24    
        End If
    What about if the shift length is Greater Than 2 hrs??



    It would be better to comment out the statements you don't want to use:
    Code:
     '   If (ShiftEndDateTime - ShiftStartDateTime) * 24 < 2 Then  
     '       ShiftLength = 2
     '   Else
    
            ShiftLength = (ShiftEndDateTime - ShiftStartDateTime) * 24    'this calculates the shift length
    
     '   End If


    I'm just sayin............

  5. #5
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Incidentally, on one person's computer, it wasn't calculating it correctly. This is what the code says:

    If (ShiftEndDateTime - ShiftStartDateTime) * 24 < 2 Then
    ShiftLength = (ShiftEndDateTime - ShiftStartDateTime) * 24

    Else
    ShiftLength = (ShiftEndDateTime - ShiftStartDateTime) * 24
    End If

    No problems, it now works on everyone's computers, regardless of the number of hours.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yep, that is another way to handle it. Although I would still have commented out the line
    Code:
    '       ShiftLength = 2
    instead of deleting it. In the future, you could see what was changed.... but that is me.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-14-2014, 03:19 PM
  2. Replies: 7
    Last Post: 10-05-2013, 08:43 AM
  3. Replies: 4
    Last Post: 08-06-2012, 10:25 AM
  4. Calculation for time x hours in table
    By hellojosie in forum Access
    Replies: 6
    Last Post: 11-20-2011, 01:54 AM
  5. Calculating Overtime hours from Time entries
    By weshader in forum Programming
    Replies: 3
    Last Post: 11-13-2011, 01:08 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