craigachan
Registered User.
- Local time
- Today, 10:11
- Joined
- Nov 9, 2007
- Messages
- 285
I'm having problems with quotation marks in a sql statement. I can't seem to figure out what my problems is. The string is an array separated by a semicolon.
120/80;70;5'6";125
this string represents patient vitals. I'm using the string to update a record. But I get hung up with the quotation mark.
I've tried: 120/80;70;5''6'"';125 which is a enclosing the quotation mark with apostrophies, but this does not seem to work. The sql still gets hung up. My sql statment looks something like:
original string: 120/80;70;5'6";125
strPreOpVits = "120/80;70;5''6'"';125"
mysql = "UPDATE mytable SET PreOpVits = '" & strPreOpVits & "' " & _
"WHERE nID = " & myRecID
docmd.runsql mysql
I've narrowed it down to the quotation marks and I'm unsure how to handle these. I get a runtime 3075 - Syntax Error. Can anyone explain what I'm doing wrong?
Here is the code that I use to convert the original string
120/80;70;5'6";125
this string represents patient vitals. I'm using the string to update a record. But I get hung up with the quotation mark.
I've tried: 120/80;70;5''6'"';125 which is a enclosing the quotation mark with apostrophies, but this does not seem to work. The sql still gets hung up. My sql statment looks something like:
original string: 120/80;70;5'6";125
strPreOpVits = "120/80;70;5''6'"';125"
mysql = "UPDATE mytable SET PreOpVits = '" & strPreOpVits & "' " & _
"WHERE nID = " & myRecID
docmd.runsql mysql
I've narrowed it down to the quotation marks and I'm unsure how to handle these. I get a runtime 3075 - Syntax Error. Can anyone explain what I'm doing wrong?
Here is the code that I use to convert the original string
Code:
Public Function FixQuotesInSql(strToFix As String)
Dim lgth, y As Long
Dim strTemp, char2Add As Variant
'This routine fixes the use of apostrophy and quotation marks in an SQL sequence
'If the apostrophy is at the beginning or end of the string it replaces with 3 x "'" or "'''"
'If in the middle of the string then replaces with 2 x "'" or "''"
'If a quotation marks occurs " then it is surrounded by '"'. Ex: My height is 5' 9" is then My height is 5''9 '"'.
lgth = Len(strToFix)
strTemp = Null
'Need to add each character or character replacement one at at time.
For y = 1 To lgth
If Mid(strToFix, y, 1) = Chr(39) Then
Select Case y
Case 1
char2Add = Chr(39) & Chr(39) & Chr(39)
Case 2 To (lgth - 1)
char2Add = "''"
Case lgth
char2Add = Chr(39) & Chr(39) & Chr(39)
End Select
Else
If Mid(strToFix, y, 1) = Chr(34) Then
char2Add = Chr(39) & Chr(34) & Chr(39)
Else
char2Add = Mid(strToFix, y, 1)
End If
End If
strTemp = strTemp & char2Add
Next y
FixQuotesInSql = strTemp
End Function