Solved Dlookup with multiple NUMBER/Integer Criteria. (1 Viewer)

Local time
Today, 00:36
Joined
May 14, 2020
Messages
32
Hey all! Hopefully something simple, I think i'm just brainfarting this code, i'm trying to use a Variable to store a Dlookup value. I want to look up the "Unit Price" of the selected item from my Purchase Orders Details table.

Code:
CurrentBuyPrice = DLookup("[Unit Price]", "[tbl_PurchaseOrdersDetails]", "[POID]= '" & CurrentPOID & "' And [ProductID]= '" & CurrentPID & "'")

I'm getting type mismatch errors, I think its how i'm using my " and ' but i cant for the life of me seem to work it out at the moment. Both CurrentPOID and CurrentPID are variables storing Integers, have already been declared and are storing information correctly (used a msgbox to check). Thanks everyone!
 

Minty

AWF VIP
Local time
Today, 00:36
Joined
Jul 26, 2013
Messages
10,371
You are surrounding your POID criteria and ProductID with ' ' making them text hence the type mismatch.
I assume they are numbers in which case remove the ' ' from your string concatenation.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:36
Joined
Feb 19, 2013
Messages
16,607
if your fields are text, you use the single quote, if they are dates you use # and if they are numbers you don't use anything. So assuming your ID's are numbers

"[POID]= " & CurrentPOID & " And [ProductID]= " & CurrentPID
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:36
Joined
Oct 29, 2018
Messages
21,467
Hi. Try removing the apostrophes in your code.

Edit: Oops, too slow.
 

Users who are viewing this thread

Top Bottom