Problem with single quoate

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Hi,

I create two dropdownmenu for list of city and country. It works if I select other city without single quote but it will not work with single quote . I am trying to add Chr(34) to make it work. Your help would be much appreciated.

example. St. Paul's

"Table1.cboCity = '" & cboCity & "' And Table.Country ='" & cboCountry & "'"
 
Put the following function in a regular module:

Public Function SingleQDouble(ByVal xstrReplaceStringValue) As String
'***THIS FUNCTION CONVERTS ONE SINGLE-QUOTE CHARACTER INTO TWO SINGLE-QUOTE
'***CHARACTERS IN A TEXT STRING.

' xstrReplaceStringValue is string variable that contains the text string
that
' needs to be converted

SingleQDouble = Replace(xstrReplaceStringValue, "'", "''")
End Function


Then change your expression in the post to this:

"Table1.cboCity = '" & SingleQDouble(cboCity) & "' And Table.Country ='" &
SingleQDouble(cboCountry) & "'"

This function replaces a single ' with two ' characters, which ACCESS will
then correctly interpret as a single ' in the text string.

--
Ken Snell
<MS ACCESS MVP>

Hi,

I create two dropdownmenu for list of city and country. It works if I
select other city without single quote but it will not work with single
quote . I am trying to add Chr(34) to make it work. Your help would be
much appreciated.

example. St. Paul's

"Table1.cboCity = '" & cboCity & "' And Table.Country ='" & cboCountry & "'"
 
Back
Top