DLookup Where Clause using OR

cstickman

Registered User.
Local time
Today, 05:16
Joined
Nov 10, 2014
Messages
109
Hey guys,

I am trying to do a DLookup, but instead of using AND use the OR in a where clause. Below is the is the string and I cannot get it to work

Code:
Me.txtdemand = DLookup("NIIN", "tblaccountnotes", "[acctnumber]= '" & Me.txtacctnum & "' AND [code]= 'Serve' OR 'XAServe'")

The table could be coded with either Serve or XAServe. We had a system design change and switched to XAServe for some reason. Right now it returns no value. Any suggestions? Thanks
 
AND and OR start entirely new comparisons. You've provided 1.5 comparisons in your code. You need to tell it what field you want to compare to 'XAServe':

"[acctnumber] = '" & Me.txtacctnum & "' OR [acctnumber] = 'XAServe'"
 
You have to put full criteria in as below, however at the moment that makes no sense
Code:
Me.txtdemand = DLookup("NIIN", "tblaccountnotes", "[acctnumber]= '" & Me.txtacctnum & "' AND  [COLOR="Red"](WHAT [/COLOR]= 'Serve' OR [COLOR="Red"]WHAT [/COLOR]=  'XAServe')")

What is the WHAT?
 
Alternatively, rather than repeating the fieldname, use the IN() function

Code:
WHAT IN('Serve', 'XAServe')
 

Users who are viewing this thread

Back
Top Bottom