sql - How to fix an error where no records come up if the phrase has an apostrophe in an MS access database? -
i have question how submit queries include apostrophe in access database. example, want search records have "women's health" in title. when try search that, no records come though there records include phrase. if search women health, records come up. how can overcome problem apostrophe?
i've tried searching previous questions , of them should use " " in sql query using , still doesn't solve problem. don't have technical background, can give me advice on how fix query can search apostrophes? query below. thanks!
select [off-site records].[file name], [off-site records].unit, [off-site records].branch, [off-site records].division, [off-site records].[date sent], [off-site records].[archives (yes/no)], [off-site records].[date range], [off-site records].[accession number], off-site records].[box #], [off-site records].[file name], [off-site records].id, [off-site records].[file name], [off-site records].[file name] [off-site records] ((([off-site records].[file name]) "" & forms!search![file name] & "") , (([off-site records].unit) "" & forms!search!unit & "") , (([off-site records].branch) "" & forms!search!branch & "") , (([off-site records].division) "" & forms!search!division & "") , (([off-site records].[date sent]) "" & forms!search![date sent] & "") , (([off-site records].[archives (yes/no)]) "" & forms!search!archives & "") , (([off-site records].[date range]) "" & forms!search![date range] & "") , (([off-site records].[accession number]) "" & forms!search![accession number] & "") , (([off-site records].[box #]) "" & forms!search![box #] & "") , (([off-site records].[file name]) "" & forms!search![file name 2] & "") , (([off-site records].[file name]) "" & forms!search![file name 3] & "") , (([off-site records].[file name]) "" & forms!search![file name 4] & ""));
instead of this:
like "" & forms!search![file name] & ""
try this:
like " & chr(34) & forms!search![file name] & chr(34) & "
that is, replace every double-quote mark belongs in final sql ascii
equivalent.
this may fix problem. if doesn't, better practice. note pertains sql in vba code.
to trouble shoot queries in access, must simplify query as can testing. if fails inserted variable, rig static query , work. if fails in vba, turn query object , work way. (use debug.print
grab final sql code run.) simplify, solve, , work way (frightfully) complicated result.
by way, can start simplifying removing every instance of [off-site records].
. you've set table name in from
clause, , because there 1 source, other uses of [off-site records].
not needed.
Comments
Post a Comment