Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Unable update table with single quot record ( ' )


Message #1 by "Mikhael Vaysband" <mvaysband@s...> on Tue, 13 Feb 2001 21:43:31
Is anyone knows why I can't update table in access when I using single 

quots (') and how can I fix this problem. Thank you.
Message #2 by "Leif N. Eriksen" <Leif_N_Eriksen@y...> on Sat, 17 Feb 2001 20:17:50
> Is anyone knows why I can't update table in access when I using single 



Actually, you can. But then you have to update the record by use of 

the "update" property of a recordset.



I believe you are trying to do it with an SQL update statement, and then 

the (')  character is interpreted as "end of line" and the SQL interpreter 

gets an invalid SQL statement.



I use the following function to check for (') within the string that I 

want to include in the SQL statement.



---------------------------------------

Function sqlSyntax(sqlString As String) As String

'Check the sql string for the character '

    Dim strTemp As String

    Dim chrPos As Long

    Dim lFor As Long



    strTemp = ""

    lFor = Len(sqlString)

    For chrPos = 1 To lFor

        strTemp = strTemp & Mid(sqlString, chrPos, 1)

        If Mid(sqlString, chrPos, 1) = "'" Then strTemp = strTemp & "'"

    Next

    sqlSyntax = "'" & strTemp & "'"

End Function

-------------------------------------------



Example:

    update myTable set myField = sqlSyntax(myString & "") where .....



I add a zero-length string to "myString" in order to cope with the cases 

where the string I want to write to the database (myString) is NULL.



Kind regards

Leif


  Return to Index