Results 1 to 10 of 10
  1. #1
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Track who made last change


    I'm getting reports of pieces of a record changing on it's own, and I want to confirm whether it's the db or user error. Is there a way to record who made a change? I can read the persons employee id into a variable just not sure how to write it when data is written to the record.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Here is an article by Allen Browne on "Creating an Audit Log" : http://allenbrowne.com/appaudit.html

    Roger Carlson also has two example dBs on creating a simple audit trail table.
    (intermediate) http://www.rogersaccesslibrary.com/forum/topic399.html
    (advanced) http://www.rogersaccesslibrary.com/forum/topic398.html

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What you want to do maybe is an audit trail or log. Here is one http://allenbrowne.com/AppAudit.html

    Otherwise, code in table BeforeUpdate data macro or form BeforeUpdate event procedure could populate a field in table with employee id.
    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.

  4. #4
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: Track who made last change

    This is for the event manager db that you helped me with in the past... I want to add an employee id and date field to each event to track the last update, even better, a separate table logging every change made to events. BeforeUpdate is called right before the db engine writes data I assume? And only for edits to existing records?

    Thanks for the link, I will test this tomorrow. Have you ever used it? And do you know how to implement the access 2010 functionality that makes it work better as described in the first section?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    There are two replies to your original post. Who helped you before?

    I've never built an audit log procedure. I have never used data macros but I expect the macro would call the VBA function code.
    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.

  6. #6
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Re: Track who made last change

    Nobody has helped me with this yet. I am referring to the data access macros, yes I agree they will probably call a VBA function, probably more efficiently.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  8. #8
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    I am using the link that you provided June, but the code is throwing an error stating it cannot run a query on a multi-value field (which is stated in your link). I do not have any multi-value fields that I am aware of--each field holds a single value. Is there a property I need to set for my fields to set them as being single-value? Does it consider text fields as multi-value? I do have an attachments field in this table, could that be it?

  9. #9
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    I tried manually selecting fields to monitor and now I am getting an error when the SQL executes:

    It looks like it is saying only insert ( audType, audDate, audUser ) and then the select statement asks for those 3 values, along with every other piece of info to record. Is this right?

    Error="Number of query values and destination fields are not the same."
    See my changes with prefix @@@
    Code:
    Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _
        lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
    
        Dim db As DAO.Database           ' Current database
        Dim sSQL As String
        'Remove any cancelled update still in the tmp table.
        Set db = DBEngine(0)(0)
        sSQL = "DELETE FROM " & sAudTmpTable & ";"
        db.Execute sSQL
        ' If this was not a new record, save the old values.
        If Not bWasNewRecord Then
            sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser ) " & _
    
                '@@@THIS LINE WAS
                '@@@"SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, " & sTable & ".*" & _
    
                'Modified to exclude attachments field
                "SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, " & _
                sTable & ".ID, " & _
                sTable & ".CompanyID, " & _
                sTable & ".EventDate, " & _
                sTable & ".EventStartTime, " & _
                sTable & ".EventEndTime, " & _
                sTable & ".EventType, " & _
                sTable & ".ScheduledBy, " & _
                sTable & ".Description, " & _
                sTable & ".NumAutoQuotes, " & _
                sTable & ".NumHomeQuotes, " & _
                sTable & ".NumBrochures, " & _
                sTable & ".Comments, " & _
                sTable & ".WasEmailSent, " & _
                sTable & ".WasMeetingSent " & _
                "FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
           
            db.Execute sSQL, dbFailOnError

  10. #10
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    Disregard, fixed this way:
    Code:
    INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser ) 
    SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, (FIELDS HERE)
    to

    Code:
    INSERT INTO " & sAudTable 
    SELECT 'EditTo' AS audType, Now() AS audDate, NetworkUserName() AS audUser, (FIELDS HERE)
    Last edited by BRZ-Ryan; 01-08-2014 at 05:11 PM.

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

Similar Threads

  1. Replies: 5
    Last Post: 07-30-2013, 01:12 PM
  2. Track employee who made changes to record.
    By FormerJarHead in forum Access
    Replies: 4
    Last Post: 01-09-2013, 04:40 PM
  3. Replies: 1
    Last Post: 08-06-2012, 08:47 AM
  4. Track change in a form
    By jmk909er in forum Forms
    Replies: 5
    Last Post: 10-19-2010, 04:05 PM
  5. Using function to track change through months
    By Accessuser in forum Programming
    Replies: 8
    Last Post: 09-28-2010, 04:09 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