Requesting Parameter Value on Update Query

G

Guest

I have an audit log that records the values of a control before and after it
is changed. The first part of the process runs on an OnDirty event to record
the value before the change and the second part runs on an AfterUpdate event
(code below).

The OnDirty part works fine, but when I try to execute the code below, I am
prompted for a parameter value. There is identical code that runs on 15
other controls with no problem. The other updates are on dates and numbers.

One interesting thing to note is that if I enter a numeric charater instead
of a text character, the code runs fine.

Private Sub txtCompanyScreened_AfterUpdate()

Dim NewVal As String

NewVal = Me.txtCompanyScreened

strSQL = "UPDATE tAuditLogTxt SET txtNewVal=" & NewVal & _
" WHERE anID=(SELECT Max(anID) FROM tAuditLogTxt WHERE txtNTName='" &
fOSUserName() & "')"

DoCmd.RunSQL strSQL

End Sub

I am running 2003 on XP.

Thoughts?

PJ
 
B

Baz

You haven't quoted NewVal properly, thus:

strSQL = "UPDATE tAuditLogTxt SET txtNewVal=""" & NewVal & _
""" WHERE anID=(SELECT Max(anID) FROM tAuditLogTxt WHERE txtNTName='" &
fOSUserName() & "')"
 
G

Guest

That did it! Thanks!

Baz said:
You haven't quoted NewVal properly, thus:

strSQL = "UPDATE tAuditLogTxt SET txtNewVal=""" & NewVal & _
""" WHERE anID=(SELECT Max(anID) FROM tAuditLogTxt WHERE txtNTName='" &
fOSUserName() & "')"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top