Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I added a table for Supervisors and made a couple of other changes...



    (Still not liking the object names - special characters and LOTS of spaces in names - both bad ideas.)

    How about this?
    Attached Files Attached Files

  2. #17
    Mearntain is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2015
    Posts
    52
    Everything seems to be working great. Thanks again for all the help. I need to work on learning some VBA myself. I know a very little, but not much at all.

  3. #18
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Great!!

    So ready to mark this solved??

  4. #19
    Mearntain is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2015
    Posts
    52
    Yes, Im looking but dont see where to mark it as solved. I thought that was something moderators did?

  5. #20
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thread tools (second green bar on the screen). Mark as solved.

  6. #21
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    I've just marked it as solved. I don't know why I'm trusted with such responsibility.

  7. #22
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't know why I'm trusted with such responsibility.
    Only you know if the question/problem has been solved to your satisfaction.
    I am confident you can handle the responsibility!

    (BTW, You can also remove the solved indication.... )

  8. #23
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Quote Originally Posted by ssanfu View Post
    Only you know if the question/problem has been solved to your satisfaction.
    This isnt my thread though! I could go and mark them all as solved it seems.

  9. #24
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Its just this thread. I've posted on another thread and i cant click "solved" on it.. strange

  10. #25
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Anyone that has posted in a thread can mark it solved/unsolved.
    Usually it is the OP that marks the thread solved......... but twice I have marked a thread solved (by request of the OP).

  11. #26
    Mearntain is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2015
    Posts
    52
    I know how to mark them solved now and will do that in the future. I now have marked the thread as UNSOLVED as I found an issue in the code that I am unsure of how to correct.

    When the code searches the table to see if it has been 90 days since the last set of points, it will give -3 points regardless of the total number of points. The max number of total points anyone can ever have is -3 points.

    For instance, Bob currently has a total of 2 points and it has been 90 days since the last entry. The code currently would add a record of -3 points which would be correct in this situation, leaving him at a final total points of -1 points.

    However, if Bob currently has a total of -1 points and it has been an additional 90 days, a record of -3 points would now give him a total of -4 points which is not OK since -3 is the lowest you can go. In this case, Bob should only have a record of -2 points added after 90 days. If he currently had a total of -2 points, a new record of only -1 points should be added at 90 days. And if he is already at a total of -3 points, a record of 0 points should be added.

    Hopefully that makes sense and someone can help with the syntax of adding that IF statement to the code to correct the issue. Thanks in advance.

    Code:
    Option Compare DatabaseOption Explicit
    
    
    Public Sub UpdatePointsDeductions()
        Dim d As DAO.Database
        Dim r As DAO.Recordset
        Dim sSQL As String
        Dim dteCurrentDate As Date
        Dim dteMaxEmpDate As Date
    
    
        Set d = CurrentDb
        dteCurrentDate = Date
    
    
        sSQL = "SELECT [Attendance Points].[Employee Name], [Attendance Points].[Supervisor Name],Sum([Attendance Points].[Points Assessed]) AS totalPts,"
        sSQL = sSQL & " Max([Attendance Points].[Day of Absence/Tardiness]) AS MaxDate"
        sSQL = sSQL & " FROM [Attendance Points]"
        sSQL = sSQL & " GROUP BY [Attendance Points].[Employee Name], [Attendance Points].[Supervisor Name]"
        sSQL = sSQL & " HAVING Sum([Attendance Points].[Points Assessed]) > -3"
        sSQL = sSQL & " ORDER BY [Attendance Points].[Employee Name];"
        '    Debug.Print sSQL
        Set r = d.OpenRecordset(sSQL)
    
    
        If r.BOF And r.EOF Then
    
    
        Else
            With r
                .MoveLast
                .MoveFirst
                Do While Not .EOF
                    dteMaxEmpDate = DateAdd("d", 90, !MaxDate)
                    If (!totalpts > -3) And (dteMaxEmpDate <= dteCurrentDate) Then
                        'add -3 points
                        sSQL = "INSERT INTO [Attendance Points] ( [Employee Name], [Supervisor Name], [Day of Absence/Tardiness], [Points Assessed], Comments )"
                        sSQL = sSQL & " VALUES ('" & ![Employee Name] & "', '" & ![Supervisor Name] & "', #" & dteMaxEmpDate & "#,  -3, '3 points deducted')"
                        '    Debug.Print sSQL
                        d.Execute sSQL, dbFailOnError
                    End If
                    .MoveNext
                Loop
            End With
        End If
    
    
        On Error Resume Next
        r.Close
        Set r = Nothing
        Set d = Nothing
    
    
    End Sub
    Last edited by Mearntain; 02-08-2017 at 12:46 PM. Reason: Added Code

  12. #27
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try these changes...also added a function to calc the points to add.

    Code:
    Public Sub UpdatePointsDeductions()
        Dim d As DAO.Database
        Dim r As DAO.Recordset
        Dim sSQL As String
        Dim dteCurrentDate As Date
        Dim dteMaxEmpDate As Date
        Dim iPoints As Integer
    
        Set d = CurrentDb
        dteCurrentDate = Date
    
        sSQL = "SELECT [Attendance Points].[Employee Name], [Attendance Points].[Supervisor Name],Sum([Attendance Points].[Points Assessed]) AS totalPts,"
        sSQL = sSQL & " Max([Attendance Points].[Day of Absence/Tardiness]) AS MaxDate"
        sSQL = sSQL & " FROM [Attendance Points]"
        sSQL = sSQL & " GROUP BY [Attendance Points].[Employee Name], [Attendance Points].[Supervisor Name]"
        sSQL = sSQL & " HAVING Sum([Attendance Points].[Points Assessed]) > -3"
        sSQL = sSQL & " ORDER BY [Attendance Points].[Employee Name];"
        '    Debug.Print sSQL
        Set r = d.OpenRecordset(sSQL)
    
        If r.BOF And r.EOF Then
    
        Else
            With r
                .MoveLast
                .MoveFirst
                Do While Not .EOF
                    dteMaxEmpDate = DateAdd("d", 90, !MaxDate)
                    If (!totalpts > -3) And (dteMaxEmpDate <= dteCurrentDate) Then
                        'add -3 points
                        iPoints = CalcPointsToAdd(!totalpts)
                        sSQL = "INSERT INTO [Attendance Points] ( [Employee Name], [Supervisor Name], [Day of Absence/Tardiness], [Points Assessed], Comments )"
                        sSQL = sSQL & " VALUES ('" & ![Employee Name] & "', '" & ![Supervisor Name] & "', #" & dteMaxEmpDate & "#, " & iPoints & ", 'Good Job! 3 points deducted.')"
                        '    Debug.Print sSQL
                        d.Execute sSQL, dbFailOnError
                    End If
                    .MoveNext
                Loop
            End With
        End If
    
        On Error Resume Next
        r.Close
        Set r = Nothing
        Set d = Nothing
    
    End Sub
    
    
    '-------new function--------
    Private Function CalcPointsToAdd(iCurPoints As Integer) As Integer
        'calculate points to add
        Dim iPointsToAdd As Integer
    
        iPointsToAdd = -3 - iCurPoints
        
        If iPointsToAdd < -3 Then
            iPointsToAdd = -3
        End If
        CalcPointsToAdd = iPointsToAdd
    End Function

  13. #28
    Mearntain is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2015
    Posts
    52
    Perfect. That looks like it did it. Thanks alot

  14. #29
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Whew!! Success at last.

    Good luck on your project.. this was fun. Made me think....

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-11-2013, 10:14 AM
  2. Calculating age during a specific time frame
    By mommaof4kids in forum Reports
    Replies: 1
    Last Post: 09-06-2012, 06:08 PM
  3. Replies: 5
    Last Post: 06-01-2012, 03:59 PM
  4. Replies: 4
    Last Post: 07-27-2011, 09:25 AM
  5. Replies: 1
    Last Post: 07-27-2011, 09:19 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