473,320 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Correct syntax for Function

I have written a short function to pass different criteria to a query.
When I use the Like operator the string is inerpreted with single
quotes i.e
QueryCriteria = "Like '" & "camera*" & "'"
is inerpreted in the query as
Like 'camera*'
The query fails to run as the query is expecting Like "camera*"
Any sugestions as to the correct syntax would be appreciated.

Jun 24 '06 #1
2 2114
JET SQL should accept the single-quote as a delimiter for a string within a
string. However, this fails as soon as a word contains an apostrophy. It is
preferable, therefore to use the double-quote.

Since VBA strings are delimited with the double-quote character, you cannot
have a string like this:
"This "word" is in quotes" ' <= error!
VBA gets to the quote before "word", thinks the string is finished, and has
no idea what to do with the rest of the line. The convention to solve this
is to double up the quote characters, so you need:
"This ""word"" is in quotes"

That looks a bit odd if the quotes come at the end of the string, because
you end up with 3 in a row:
"This ""word"""

So you need:
QueryCriteria = "Like ""camera*"""

Or, if the search word is in the text box named Text0:
QueryCriteria = "Like """ & [Text0] & "*"""

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<mi*********@gmail.com> wrote in message
news:11********************@g10g2000cwb.googlegrou ps.com...
I have written a short function to pass different criteria to a query.
When I use the Like operator the string is inerpreted with single
quotes i.e
QueryCriteria = "Like '" & "camera*" & "'"
is inerpreted in the query as
Like 'camera*'
The query fails to run as the query is expecting Like "camera*"
Any sugestions as to the correct syntax would be appreciated.

Jun 24 '06 #2
Thanks Allen, I appreciate the help

Allen Browne wrote:
JET SQL should accept the single-quote as a delimiter for a string within a
string. However, this fails as soon as a word contains an apostrophy. It is
preferable, therefore to use the double-quote.

Since VBA strings are delimited with the double-quote character, you cannot
have a string like this:
"This "word" is in quotes" ' <= error!
VBA gets to the quote before "word", thinks the string is finished, and has
no idea what to do with the rest of the line. The convention to solve this
is to double up the quote characters, so you need:
"This ""word"" is in quotes"

That looks a bit odd if the quotes come at the end of the string, because
you end up with 3 in a row:
"This ""word"""

So you need:
QueryCriteria = "Like ""camera*"""

Or, if the search word is in the text box named Text0:
QueryCriteria = "Like """ & [Text0] & "*"""

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<mi*********@gmail.com> wrote in message
news:11********************@g10g2000cwb.googlegrou ps.com...
I have written a short function to pass different criteria to a query.
When I use the Like operator the string is inerpreted with single
quotes i.e
QueryCriteria = "Like '" & "camera*" & "'"
is inerpreted in the query as
Like 'camera*'
The query fails to run as the query is expecting Like "camera*"
Any sugestions as to the correct syntax would be appreciated.


Jun 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
5
by: Oplec | last post by:
Hi, I am trying to figure out the correct syntax for declaring a friend function in a class template and then defining that member after the class. The code example below is what I am trying to get...
1
by: Greg | last post by:
I have the following code (a one line function) I'm trying to calculate a value for text field matPerPiece# where # is a row number I provide. The value is calculated from text fields...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
53
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document,...
6
by: Rob Thorpe | last post by:
Given the code:- r = sscanf (s, "%lf", x); What is the correct output if the string s is simply "-" ? If "-" is considered the beginning of a number, that has been cut-short then the...
2
by: MLH | last post by:
SendMailPlusWithOE Subject, Message, Recipients, Files, "08" I've seen the above syntax used to call the sub SendMailPlusWithOE Is it correct/incorrect/good practice/bad practice or just a...
1
by: sruthykmenon | last post by:
what is the correct syntax for calling function/procedure in a stored procedure?? when there is a package called 'ABC' procedure 'DEF' function 'KLM'
2
by: Andy Champ | last post by:
We have a class with something that, simplified, looks like this: template <typename Tclass foo { T beyondAllReaching; // In VC2005, this works OK template <typename Ufriend void...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.