Private Sub butnRemove_Click()
Dim strUpdate As String, strDelete As String
Dim ctl As Control
Dim strSet As String
Dim bFirst As Boolean
Dim iResponse As Integer
'1. delete from the master table
strDelete = "DELETE * FROM tblMaster"
bFirst = True
'2. Ask the question to confirm delete before deleting anything!
iResponse = MsgBox("Are you sure you want to delete record ID " & ID & "?", vbYesNo)
If (iResponse = vbNo) Then
Me.Undo
Exit Sub
End If
'3. Adjust the Capacity Field value to 0 so the AuditTrail will acknowledge a change
For Each ctl In Me.Controls
With ctl
If .ControlType = acTextBox Then
If .Name = "Capacity" Then
.Value = "0"
End If
End If
End With
Next
Set ctl = Nothing
'4. Update the Audit Table
Call AuditTrail(Me, ID)
'5. Delete item from tblMaster
strDelete = strDelete & " where ID = " & ID.Value
Debug.Print strDelete
DoCmd.SetWarnings False
DoCmd.RunSQL strDelete
DoCmd.SetWarnings True
'6. Update Changes table to remove the same record from the changes table
strDelete = "DELETE * FROM Changes" & " where ID = " & ID.Value
Debug.Print strDelete
DoCmd.SetWarnings False
DoCmd.RunSQL strDelete
DoCmd.SetWarnings True
DoCmd.RunCommand acCmdRecordsGoToNext
' Refresh the table in the Change Master Record Form, adjust which record is selected, so it appropriate.
Me.Refresh
End Sub