Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transmitting the value of a field

Status
Not open for further replies.

newguy86

Technical User
May 19, 2008
226
US
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
 

Is Job Number a text field?
If not, remove the single quotes around it.


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top