UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Dllokup On Stings Containing An Apostrophe, Office 2010    
 
   
TimTDP
post Mar 17 2012, 12:58 AM
Post #1

UtterAccess Guru
Posts: 677



How do I perform a dlookup on strings containing an apostrophe?

eg
strCtriteria = "Apple"
ProductId = dlookup("ProductId","tblProduct","Product = '" & strCtriteria & "'") works

but if
strCtriteria = "Apple's"
ProductId = dlookup("ProductId","tblProduct","Product = '" & strCtriteria & "'") fails - syntax error (missing operator) in query expression......

How do I get the dlookup function to work if strCtriteria contains characters like ' or " (or any other funny character that will effect the dlookup)
What if strCtriteria contains multiple funny characters?
I also never know the position of the funny character in the string!

Thanks in advance

This post has been edited by TimTDP: Mar 17 2012, 12:59 AM
Go to the top of the page
 
+
theDBguy
post Mar 17 2012, 01:02 AM
Post #2

Access Wiki and Forums Moderator
Posts: 47,947
From: SoCal, USA



Hi Tim,

Just double-up the apostrophes. For example:

CODE
strCriteria = "Apple''s"

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
TimTDP
post Mar 17 2012, 01:55 AM
Post #3

UtterAccess Guru
Posts: 677



what funny characters do I need to watch out for?
Go to the top of the page
 
+
Alan_G
post Mar 17 2012, 03:17 AM
Post #4

Utterly Yorkshire and Forum/Wiki Editor
Posts: 15,882
From: Devon UK



Hi

The biggest culprits are the single and double quotes in text strings
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 21st May 2013 - 11:15 AM