This topic is locked

Error with event when field string contains a single quote

1/29/2007 12:36:49 PM
ASPRunnerPro General questions
C
clig author

For example we have an event such as:
Function BeforeEdit(dict, where)
' Parameters:

' dict - Scripting.Dictionary object.

' Each field on the Edit form represented as 'Field name'-'Field value' pair

' where - string with WHERE clause pointing to record to be edited
dict("Last Modified") = strUserID & " - " & Now()

dict("CSR") = strUserID

dict("Status") = "2"

dict("Resolution Date") = Now()
'** Save new data in another table ****

strSQLSave = "INSERT INTO [CSR Records] (Project, Sims, ProblemDescription, Technician, [Tech Support], Priority, Severity, TechSuppRegion, ExtraDetail, SYSType) values ("

strSQLSave = strSQLSave & "'" & cstr(dict("Project")) & "', '"

strSQLSave = strSQLSave & cstr(dict("Sims")) & "', '"

strSQLSave = strSQLSave & "Referral - " & dict("ProblemDescription") & "', "

strSQLSave = strSQLSave & dict("Technician") & ", '"

strSQLSave = strSQLSave & dict("CSR") & "', '"

strSQLSave = strSQLSave & dict("Priority") & "', '"

strSQLSave = strSQLSave & dict("Severity") & "', '"

strSQLSave = strSQLSave & dict("TechSuppRegion") & "', '"

strSQLSave = strSQLSave & dict("ExtraDetail") & "', '"

strSQLSave = strSQLSave & "Referral"

strSQLSave = strSQLSave & "')"

dbConnection.Execute strSQLSave
BeforeEdit = True
' set BeforeEdit to True if you like to proceed with editing this record

' set it to False in other case

End Function

  • ExtraDetail field has a value of "Joe's garage" - the above event stops with error at 's'
  • I haven't tried anything yet but I'd assume something like a REPLACE on the string would be in order here?
  • Something like:
    EDFix = Replace(dict("ExtraDetail") , "'", "")

C
clig author 1/29/2007

Function BeforeEdit(dict, where)
dict("Last Modified") = strUserID & " - " & Now()

dict("CSR") = strUserID

dict("Status") = "2"

dict("Resolution Date") = Now()
strSQLSave = "INSERT INTO [CSR Records] (Project, Sims, ProblemDescription, Technician, [Tech Support], Priority, Severity, TechSuppRegion, ExtraDetail, SYSType) values ("

strSQLSave = strSQLSave & "'" & cstr(dict("Project")) & "', '"

strSQLSave = strSQLSave & cstr(dict("Sims")) & "', '"

strSQLSave = strSQLSave & "Referral - " & Replace(dict("ProblemDescription") , "'", "") & "', "

strSQLSave = strSQLSave & dict("Technician") & ", '"

strSQLSave = strSQLSave & dict("CSR") & "', '"

strSQLSave = strSQLSave & dict("Priority") & "', '"

strSQLSave = strSQLSave & dict("Severity") & "', '"

strSQLSave = strSQLSave & dict("TechSuppRegion") & "', '"

strSQLSave = strSQLSave & Replace(dict("ExtraDetail") , "'", "") & "', '"

strSQLSave = strSQLSave & "Referral"

strSQLSave = strSQLSave & "')"

dbConnection.Execute strSQLSave
BeforeEdit = True

End Function

  • works...