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

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Quotes In Dlookup, Office 2007    
 
   
eacollie
post Apr 3 2012, 07:45 PM
Post #1

UtterAccess Veteran
Posts: 408
From: Tennessee



Can someone be so kind as to help in setting the quotation marks correctly in this line of code:

CODE
        res = DLookup("[RoomRequestID]", "qryReservationsMC",  "[OrganizationIndividual] = """ & strOrganizationIndividual & """ AND [FunctionType] = " & iFunctionType & " AND [StartDate] = " & dtCriteria1)


Thank you.
Go to the top of the page
 
+
Alan_G
post Apr 3 2012, 07:49 PM
Post #2

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



Hi

Guessing that the data types are text, numerical and date/time it would be

CODE
res = DLookup("[RoomRequestID]", "qryReservationsMC",  "[OrganizationIndividual] = '" & strOrganizationIndividual & "' AND [FunctionType] = " _
& iFunctionType & " AND [StartDate] = #" & dtCriteria1 & "#")

Go to the top of the page
 
+
Scot
post Apr 3 2012, 07:51 PM
Post #3

UtterAccess Guru
Posts: 752
From: Silver Spring Maryland, USA



CODE
DLookup("[RoomRequestID]", "qryReservationsMC", "[OrganizationIndividual] = " & strOrganizationIndividual & " AND [FunctionType] = " & iFunctionType & " AND [StartDate] # "& dtCriterial & "#")


Looks right...

EDIT: Ah, missed the single quotes.

This post has been edited by Scot: Apr 3 2012, 07:52 PM
Go to the top of the page
 
+
eacollie
post Apr 3 2012, 07:58 PM
Post #4

UtterAccess Veteran
Posts: 408
From: Tennessee



Thanks Alan....that fixed it!
Go to the top of the page
 
+
Alan_G
post Apr 3 2012, 08:01 PM
Post #5

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



(IMG:style_emoticons/default/yw.gif)
Go to the top of the page
 
+
datAdrenaline
post Apr 3 2012, 09:49 PM
Post #6

UtterAccess Editor
Posts: 15,978
From: Northern Virginia, USA



I know you have found a solution to your immediate issue, but I thought it would be appropriate to relay this concept that goes deeper than a one time fix, because if your literal string has a single hash, you will be right back at square one. So here is the concept: Double up your delimiter in the string being sought.

Example:

If you use the single hash (') as your literal string delimiter in your SQL statement (or filter argument of a DLookup), then double-up the single hash in the string being sought ...
CODE
"SELECT * FROM someTable WHERE someTextField = '" & Replace(stringVariable,"'","''") & "'"


Or with DLookup()
CODE
DLookup("[RoomRequestID]", "qryReservationsMC",  "[OrganizationIndividual] = '" & Replace(strOrganizationIndividual,"'","''") & "'")


If you use the double quote (") as your literal string delimiter in your SQL statement (or filter argument of a DLookup), then double-up the double quote in the string being sought ...
CODE
"SELECT * FROM someTable WHERE someTextField = """ & Replace(stringVariable,"""","""""") & """"


Or with DLookup()
CODE
DLookup("[RoomRequestID]", "qryReservationsMC",  "[OrganizationIndividual] = """ & Replace(strOrganizationIndividual,"""","""""") & """")
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: 25th May 2013 - 03:40 AM