Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use ' in a query??? 1

Status
Not open for further replies.

logge

Programmer
Jun 16, 2000
6
NL
Hi!

I have a database containing filenames, and some of them uses the ' character. (ex. "peter's file.txt")
I'm using a MFC recordset to connect to the database.

Problem is that when I want to filter records Access don't like strings with ' at all, since it thinks this is the end of a string, and not a character in the string.

Does anyone know how to fix this?

Thanks,

Peter Logarn
 
Sure!

If I try to do something like this:

m_pSet->m_strFilter = "TYPE = 'Peter's file.txt'";
m_pSet->Requery();

I get an exception when I do the Requery() call,
saying something about a invalid query.

m_pSet is from a CRecordSet derived class.

I hope this will help.
 
Hallo,

Try replacing the ' String delimiters in the SQL with "". You have to do "" rather than " so Access knows it's the " character, not the end of the string. Like this:

m_pSet->m_strFilter = "TYPE = ""Peter's file.txt""";

- Frink
 
Sorry, it does not work.

It just says "Syntax error in string in query expression 'TYPE = Peter's file.txt ORDER BY ID'.

Peter
 
Hallo,

Sorry about that. I'll summarise the suggested FAQ, by saying just add more "s until it works.

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top