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