DLookup on 3 numeric fields

Malcy

Registered User.
Local time
Today, 21:14
Joined
Mar 25, 2003
Messages
584
Hi
Hope someone can help since I have got an error in my code. I know it lies in the middle part around Me.cboSupplier since when I break and hover over all the other bits they give me the right values but when I hover over Me.cboSupplier I get zilch.
The line of code is
Code:
lngQuote = DLookup("lngQuId", "tblQuotes", "[lngQuMonth] =" & Me.txtMonthID And [lngQuSup] = " & Me.cboSupplier & " And "[lngQuDrug] =" & Me.cboDrug & "")
I suspect I could go on trying variations for ever and really got to here by finding it put both "and"s in blue and did not put the whole line in red, so something must be right, but not what I am wanting!!
Any help would be most appreciated
Best wishes
 
DLookup(...,"string part here" & variable & "more string" & AnotherVariable & "rest of string" & LastVariable

ONLY the variables/form references should be outside the quotes. See how yours is different?
 
Couldn't resist...

Code:
lngQuote = DLookup("[lngQuId]", "tblQuotes", "[lngQuMonth]=" & Me.txtMonthID & " And [lngQuSup]=" & Me.cboSupplier & " And [lngQuDrug]=" & Me.cboDrug)

Note that if any of your criteria (txtMonthID, cboSupplier, and cboDrug) are text, you will need single quotes around them. Going by variable name, I'm guessing txtMonthID would be text, which would change you DLookup to look like this:

Code:
lngQuote = DLookup("[lngQuId]", "tblQuotes", "[lngQuMonth]=[COLOR="Red"]'[/COLOR]" & Me.txtMonthID & "[COLOR="Red"]'[/COLOR] And [lngQuSup]=" & Me.cboSupplier & " And [lngQuDrug]=" & Me.cboDrug)
 
Thanks guys
I can almost follow the logic and will probably continue to do so until I need to use it again!
THanks especially for between you providing both the "this is how it works" answer and the "this is what it is" answer. That actually helped a lot because I could work through the line and see how the quotes were working, which I confess I have always found very difficult.
Best wishes
 

Users who are viewing this thread

Back
Top Bottom