Results 1 to 3 of 3
  1. #1
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218

    Prevent audit logger from logging if no changes were made


    I've got a (hopefully) small problem. I've built this form which allows me to change information assigned to Equipment. That is, where its located (Building, Room, Cabinet), as well as logical information (Hostname, IP address, etc). I'm using Allen Browne's audit logger to log any changes made on the form. The only thing I've noticed about it is that if I hit "Save" and then because I'm a potential user and therefore stupid, I hit "save" again, it will log two records which are identical. How can I resolve this issue?

    Here's my code for the form:

    Code:
    Option Compare Database
    Dim bWasNewRecord As Boolean
    
    
    
    
    Private Sub cboBuildingName_AfterUpdate()
            Me.cboRoomName.Requery
    End Sub
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        bWasNewRecord = Me.NewRecord
        Call AuditEditBegin("tblEquipment", "audTmpEquipment", "EquipmentPK", Nz(Me.txtEquipmentPK, 0), bWasNewRecord)
    End Sub
    Private Sub Form_AfterUpdate()
        Call AuditEditEnd("tblEquipment", "audTmpEquipment", "audEquipment", "EquipmentPK", Nz(Me!txtEquipmentPK, 0), bWasNewRecord)
    End Sub
    
    
    Private Sub toStorage()
         Set db = CurrentDb
         Set rs = db.OpenRecordset("SELECT * FROM tblEquipment WHERE EquipmentPK = " & txtEquipmentPK)
         With rs
     .Edit
       .Fields("CabinetFK") = Null
       .Fields("EquipmentName") = Null
       .Fields("EquipmentIP") = Null
       .Fields("EquipmentNetworkTypeFK") = Null
       .Fields("SoftwareVersionFK") = Null
     .Update
    End With
    End Sub
    Private Sub cboEquipmentStatus_AfterUpdate()
       ' Me.Dirty = False
    End Sub
    
    
    Private Sub cboRoomName_AfterUpdate()
            Me.cboCabinetName.Requery
    End Sub
    
    
    Private Sub cmdAddRoom_Click()
        DoCmd.OpenForm "frmPopUpChangeRoom", , , "RoomPK = " & Me.txtRoomFK
    End Sub
    
    
    Private Sub cmdSave_Click()
             Dim ctl As Control
             Dim myForm As Form
             Set myForm = Me.Form
             Dim inStorage As Boolean
             inStorage = False
             inStorage = inStorage Or Me.cboEquipmentStatus.Value = 2
             inStorage = inStorage Or Me.cboEquipmentStatus.Value = 3
             For Each ctl In myForm
                  If InStr(1, ctl.Tag, "*") <> 0 Then
                      If ctl.Value <> ctl.OldValue Then
                          Me.txtDateUpdated = Date
                      End If
                  End If
                  If InStr(1, ctl.Tag, "&") <> 0 Then
                      If inStorage And ctl.Value <> ctl.OldValue Then
                          If MsgBox("WARNING!! Changing Equipment status to In Storage will remove all Logial Equipment Information as well as the Room its assigned to." _
                          & " Are you sure you want to proceed?", vbYesNo) = vbYes Then
                              Me.txtDateUninstalled = Date
                              MsgBox "Uninstalled Date Updated"
                              Me.Dirty = False
                              Call toStorage
                          Else
                              Me.Undo
                          End If
                      ElseIf Not inStorage Then
                          If IsNull(Me.txtEquipmentName.Value) Or (Me.txtEquipmentName.Value) = "" _
                          Or IsNull(Me.txtEquipmentIP.Value) Or (Me.txtEquipmentIP.Value) = "" _
                          Or IsNull(Me.cboSoftwareVersion.Value) Or (Me.cboSoftwareVersion.Value) = "" _
                          Or IsNull(Me.cboCabinetName.Value) Or (Me.cboCabinetName.Value) = "" Then
                              If MsgBox("If Equipment Status is Operational, Logical Information and Physical Location cannot be blank. Do you want to try again?", vbYesNo) = vbYes Then
                             
                              Else
                                  Me.Undo
                              End If
                          Else
                              Me.txtDateInstalled = Date
                          End If
                      End If
                  End If
             Next
             DoCmd.RunCommand acCmdSaveRecord
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Maybe use another global Boolean that flags an existing record has been edited. Or maybe just simply check if the record is 'dirty':

    If Me.Dirty Then
    ...

    Maybe disable the Save button in the form AfterUpdate event. Enable it only when record is 'dirty'.
    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
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    If Me.Dirty seems to do the trick. Thanks!

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

Similar Threads

  1. How to record time logs after logging in and logging out
    By annayanagi014 in forum Programming
    Replies: 1
    Last Post: 02-18-2015, 07:52 AM
  2. Replies: 2
    Last Post: 12-13-2014, 11:45 AM
  3. Replies: 2
    Last Post: 04-16-2014, 11:17 AM
  4. Replies: 2
    Last Post: 02-09-2013, 12:39 PM
  5. Logging Changes
    By nichmeg in forum Programming
    Replies: 0
    Last Post: 12-06-2011, 02:47 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