Insert Query Problem with Apostrophes and Quotes

P

Pete

We have an application with an audit table to keep track of who changed what
and when. This is updated using the following code:
Dim cmd1 As ADODB.Command
Set cmd1 = New ADODB.Command
With cmd1
.ActiveConnection = CurrentProject.Connection
'.CommandText = "INSERT INTO tblAuditTrail(cUserCode, dDateTime,
cChange) VALUES ('" & CurrentUser & "', #" & Now() & “#, “ & Chr(34) &
RecordChanged & Chr(34) & ")"
.CommandType = adCmdText
.Execute
End With
Set cmd1 = Nothing

The Chr(34)s were added as I ran into problem if the value of the
RecordChanged string contained an apostrophe (').

I now have a problem as a user wants to write a record containg quotes (")
and an apostrophe ('). I have written a function that strips these characters
out of the string, but ideally I would like to audit exactly what the user
has entered. I have tried playing around with adding Chr(39) into the above
CommandText but not had any luck. Help please!
 

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