I'm trying to write a partial text match, to filter a form, from a combobox.
This is what I was working on writing:
"[FieldName1] Like '*" & Replace(Me.cboFindRecord.Text, "'", """) & "*' OR [FieldName2] Like '*" & Replace(Me.cboFindRecord.Text, "'", """) & "*'"
When I leave that line of the VBA code, I get an error at the 2nd & "*', highlighting the single quote ', and it says Compile error: Expected expression.
Anyone know what I'm doing wrong? I've checked the quotes and double quotes again and again.
, """)
is not a valid string.
If you want to use a double quote character, it would be
"[FieldName1] Like '*" & Replace(Me.cboFindRecord.Text, "'", """") & "*' OR ..."
(an escaped double quote inside a string)
But the usual way of escaping single quotes is to use two single quotes:
"[FieldName1] Like '*" & Replace(Me.cboFindRecord.Text, "'", "''") & "*' OR ..."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.