special characters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a string variable (StrErrorDescription). This variable is sourced via
referencing the ERR.Description. When an error occurs because a form cannot
be seen. The error says "The form 'xxxx' cannot be seen"

(note the additonal ' symbols in the error description, as this causes my
error)

I am trying to write this to my table in a SQL statement as per below:

DoCmd.RunSQL "INSERT INTO TBL_SYS_ERROR_LOG ( Error_Date, USER_ID,
APPLICATION_NAME, PROCEDURE_NAME, VB_ERROR_NUMBER, VB_ERROR_DESCRIPTION )
SELECT Now(), '" & fOSUserName & "', '" & Logname & "','" &
StrCurrentProcedureName & "', '" & StrErrorNo & "', '" & StrErrorDescription
& "';"

This doesn't handle the additional ' symbols in the error description. Any
suggestions for a solution would be appreciated.

Thanks
 
Why not just use:
Replace(StrErrorDescription,"'","")

It will remove all of the ' characters from the string
 
You can double the single quote:

Replace([StrErrorDescription],"'","''")



DoCmd.RunSQL "INSERT INTO TBL_SYS_ERROR_LOG ( Error_Date, USER_ID,
APPLICATION_NAME, PROCEDURE_NAME, VB_ERROR_NUMBER, VB_ERROR_DESCRIPTION )
SELECT Now(), '" & fOSUserName & "', '" & Logname & "','" &
StrCurrentProcedureName & "', '" & StrErrorNo & "', '" &
Replace([StrErrorDescription] , "'","''") & "';"
 
Thanks for the assistance.

My issue with using the Replace method is that is doesn't cater for all
possible special characters..

Is there another way of handling special characters?

Ofer Cohen said:
You can double the single quote:

Replace([StrErrorDescription],"'","''")



DoCmd.RunSQL "INSERT INTO TBL_SYS_ERROR_LOG ( Error_Date, USER_ID,
APPLICATION_NAME, PROCEDURE_NAME, VB_ERROR_NUMBER, VB_ERROR_DESCRIPTION )
SELECT Now(), '" & fOSUserName & "', '" & Logname & "','" &
StrCurrentProcedureName & "', '" & StrErrorNo & "', '" &
Replace([StrErrorDescription] , "'","''") & "';"

--
Good Luck
BS"D


NeilGel said:
Hi,

I have a string variable (StrErrorDescription). This variable is sourced via
referencing the ERR.Description. When an error occurs because a form cannot
be seen. The error says "The form 'xxxx' cannot be seen"

(note the additonal ' symbols in the error description, as this causes my
error)

I am trying to write this to my table in a SQL statement as per below:

DoCmd.RunSQL "INSERT INTO TBL_SYS_ERROR_LOG ( Error_Date, USER_ID,
APPLICATION_NAME, PROCEDURE_NAME, VB_ERROR_NUMBER, VB_ERROR_DESCRIPTION )
SELECT Now(), '" & fOSUserName & "', '" & Logname & "','" &
StrCurrentProcedureName & "', '" & StrErrorNo & "', '" & StrErrorDescription
& "';"

This doesn't handle the additional ' symbols in the error description. Any
suggestions for a solution would be appreciated.

Thanks
 
Back
Top