Hi guys,
Not sure if I should be asking this here or in Queries, but maybe someone can help me out.
I am trying to run an Audit Trail module on an Invoice form to keep track of changes. The same module works fine with several of my other forms, and my Invoice form doesn't cause any errors when I don't have the Audit Trail running. I am no expert and am not sure what to do to solve this! Here is the SQL for the form's record source query, which is what causes the error:
Here is the Audit Trail code that works on other forms:
And I have the Audit Trail Module set to run in the form's BeforeUpdate Event like so (which is successful in my other forms where I use the module):
Any ideas for me? TIA!!
Not sure if I should be asking this here or in Queries, but maybe someone can help me out.
I am trying to run an Audit Trail module on an Invoice form to keep track of changes. The same module works fine with several of my other forms, and my Invoice form doesn't cause any errors when I don't have the Audit Trail running. I am no expert and am not sure what to do to solve this! Here is the SQL for the form's record source query, which is what causes the error:
Code:
SELECT tblInvoice.*, tblAssignment.RateOut, tblTaskOrder.TaskOrderID, tblTaskOrder.TaskOrderName, tblPeople.PeopleID, tblPeople.[Firstname] & " " & [Lastname] AS FullName, tblVendor.VendorName
FROM (((tblInvoice INNER JOIN tblAssignment ON tblInvoice.AssignmentID = tblAssignment.AssignmentID) INNER JOIN tblTaskOrder ON tblAssignment.TaskOrderID = tblTaskOrder.TaskOrderID) INNER JOIN tblPeople ON tblAssignment.PeopleID = tblPeople.PeopleID) INNER JOIN tblVendor ON tblPeople.Vendor = tblVendor.VendorID;
Here is the Audit Trail code that works on other forms:
Code:
Option Compare Database
Option Explicit
Const cDQ As String = """"
Sub AuditTrail(frm As Form, recordid As Control)
'Track changes to data.
'recordid identifies the pk field's corresponding
'control in frm, in order to id record.
Dim ctl As Control
Dim varBefore As Variant
Dim varAfter As Variant
Dim strControlName As String
Dim strSQL As String
On Error GoTo ErrHandler
'Get changed values.
For Each ctl In frm.Controls
With ctl
'Avoid labels and other controls with Value property.
If .ControlType = acTextBox Then
If .Value <> .OldValue Then
varBefore = .OldValue
varAfter = .Value
strControlName = .Name
'Build INSERT INTO statement.
strSQL = "INSERT INTO " _
& "tblAudit (EditDate, RecordID, SourceTable, " _
& " SourceField, BeforeValue, AfterValue) " _
& "VALUES (Now()," _
& cDQ & recordid.Value & cDQ & ", " _
& cDQ & frm.RecordSource & cDQ & ", " _
& cDQ & .Name & cDQ & ", " _
& cDQ & varBefore & cDQ & ", " _
& cDQ & varAfter & cDQ & ")"
'View evaluated statement in Immediate window.
Debug.Print strSQL
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End If
End If
End With
Next
Set ctl = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description & vbNewLine _
& Err.Number, vbOKOnly, "Error"
End Sub
And I have the Audit Trail Module set to run in the form's BeforeUpdate Event like so (which is successful in my other forms where I use the module):
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Call AuditTrail(Me, InvoiceID)
End Sub
Any ideas for me? TIA!!