473,769 Members | 5,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2152
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*********@gm ail.com> wrote in message
news:11******** ************@g1 0g2000cwb.googl egroups.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*********@gm ail.com> wrote in message
news:11******** ************@g1 0g2000cwb.googl egroups.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
2477
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" for when and how to use single quotes and double quotes in ASP? thanks! ---------------------- SQL = SQL & "WHERE '" & REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE("GenKTitles.
5
8960
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 to work properly; it generates a link error. Thank you, Oplec. #include <cstdlib>
1
4796
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 matPOTotal# and QuantityMade. The elements exist in a form named costsheet function mattotalrow(rowNumber) { document.getElementsById('matPerPiece' + rowNumber).value =
19
2975
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 $ Last-Modified: $Date: 2003/09/22 04:51:49 $ Author: Nicolas Fleury <nidoizo at gmail.com> Status: Draft Type: Standards Track
53
4600
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, and at the end there is even pure mindstorming text left in, but already I think it can be very useful. <url: http://home.no.net/dubjai/win32cpptut/special/pointers/preview/pointers_01__alpha.doc.pdf>.
6
3489
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 correct output is that r = EOF. If it is taken to be a letter in the stream, then the output should be r = 0, as far as I can see. My compiler gives EOF.
2
1340
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 matter of personal preference?
1
1797
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
1694
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 method(foo<Tl, foo<Ur); // But VC2008 requires this
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.