Here is what I am trying to accomplish. I wanted to create a log that tracks any changes to a record in my database. I have everything setup except for one issue. I cannot get my macro to transmit the value of 'Job_Number' into my log so that I know which record has been edited. Here is my code and if anyone can help that would be greatly appreciated.
<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
bOK = False
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, FieldChanged, FieldChangedFrom, FieldChangedTo, User, DateofHit) " & _
"SELECT" & "'" & Job_Number & "', " & _
"'" & ctlC.Name & "', " & _
"'" & ctlC.OldValue & "', " & _
"'" & ctlC.Value & "', " & _
"'" & GetUserName_TSB() & "', " & _
"'" & Now() & "'"
'Debug.Print strSQL
DoCmd.RunSQL strSQL
End If
End If
End If
Next ctlC
.
.
.
End Function
</code>
If you have any question feel free to let me know.
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
bOK = False
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, FieldChanged, FieldChangedFrom, FieldChangedTo, User, DateofHit) " & _
"SELECT" & "'" & Job_Number & "', " & _
"'" & ctlC.Name & "', " & _
"'" & ctlC.OldValue & "', " & _
"'" & ctlC.Value & "', " & _
"'" & GetUserName_TSB() & "', " & _
"'" & Now() & "'"
'Debug.Print strSQL
DoCmd.RunSQL strSQL
End If
End If
End If
Next ctlC
.
.
.
End Function
</code>
If you have any question feel free to let me know.
Travis