I am trying to create a log that will automatically record any changes to data in a table. But whenever I try to run the logger I keep getting the error message "Syntax error in INSERT INTO statement". I have tried to see what each value is before the SQL statement runs to make sure that the code can read the data correctly and each item comes back perfectly fine. Here is the code if anyone would be able to help out in resolving this.
Travis
Code:
Public Function WriteAudit(frm As Form, lngID As Long) As Boolean
On Error GoTo err_WriteAudit
Dim ctlC As Control
Dim fldF As Field
Dim strSQL As String
Dim bOK As Boolean
Dim strFormID As String
bOK = False
strFormID = "05"
DoCmd.SetWarnings False
' For each control.
For Each ctlC In frm.Controls
If TypeOf ctlC Is TextBox Or TypeOf ctlC Is ComboBox Then
If ctlC.Value <> ctlC.OldValue Or IsNull(ctlC.OldValue) Then
If Not IsNull(ctlC.Value) Then
strSQL = "INSERT INTO tblDbLog (RecordID, UserID, Db-FrmID, ActivityID, FieldChanged, FieldChangedFrom, FieldChangedTo, DateofHit) " & _
"SELECT" & "'" & Form_Complaints.Incident_Number & "', " & _
"'" & GetUserName_TSB() & "', " & _
"'" & "04" & strFormID & "', " & _
"'" & "01" & "', " & _
"'" & ctlC.Name & "', " & _
"'" & ctlC.OldValue & "', " & _
"'" & ctlC.Value & "', " & _
"'" & Now() & "'"
'Debug.Print strSQL
DoCmd.RunSQL strSQL
End If
End If
End If
Next ctlC
WriteAudit = bOK
exit_WriteAudit:
DoCmd.SetWarnings True
Exit Function
err_WriteAudit:
MsgBox Err.Description
Resume exit_WriteAudit
End Function
Travis