Run time error in multiple criteria DLookup (1 Viewer)

jibb

Registered User.
Local time
Yesterday, 20:00
Joined
Dec 1, 2011
Messages
93
I have got the following lookup on my form:

Code:
Me.PALLET_QUANTITY = DLookup("[PALLET QTY]", "tblSupplierPalletQty", "[STOCK CODE]=" & Forms![ENTER PURCHASE ORDER]![PRODUCT CODE] & " And [SUPPLIER]=" & Forms![ENTER PURCHASE ORDER]![ACC NO] & "")

to find the pallet quantity of a product for a specific supplier, but every time I run it, it comes up with the following error -

"Run-time error '3075':

Syntax error (missing operator0 in query expression '[STOCK CODE]=112204CBC And [SUPPLIER]=HAREUR'. "

Any ideas why??
 

sparks80

Physicist
Local time
Today, 04:00
Joined
Mar 31, 2012
Messages
223
Hi,

Try putting single quotation marks around the text string you are entering for the supplier like this:

Code:
Me.PALLET_QUANTITY = DLookup("[PALLET QTY]", "tblSupplierPalletQty", "[STOCK CODE]=" & Forms![ENTER PURCHASE ORDER]![PRODUCT CODE] & " And [SUPPLIER]=[SIZE=3][COLOR=magenta]'[/COLOR][/SIZE]" & Forms![ENTER PURCHASE ORDER]![ACC NO] & "[SIZE=3][COLOR=magenta]'[/COLOR][/SIZE]")
 

jibb

Registered User.
Local time
Yesterday, 20:00
Joined
Dec 1, 2011
Messages
93
That returns the same error but with an ' in front of the "HAREUR" in the error.

It doesn't seem to be picking up the "and" as an operator.
 

spikepl

Eledittingent Beliped
Local time
Today, 05:00
Joined
Nov 3, 2010
Messages
6,142
You have put 2 things together, and you don't know whether it is one, or the other or the combination that does not work. To find out, make a dlookup just depending on one criterion, make it work. Then the other. Once the two each do their job, then combine. This way you always know what failed.

This is a very common error here: ppl put complex things together and are lost, when it doesn't work. ONE STEP AT A TIME will save you lots of grief.
 

jibb

Registered User.
Local time
Yesterday, 20:00
Joined
Dec 1, 2011
Messages
93
Ok!

I have made each half of the formula work and put them together, but it now just says "Run-time error 13: type mismatch"
 

spikepl

Eledittingent Beliped
Local time
Today, 05:00
Joined
Nov 3, 2010
Messages
6,142
Oh yeah. "I have done ¤"#&%#¤"&#"#&¤!" and it doesn't work: :D

ALways show the code, because that will always be the next question.
 

jibb

Registered User.
Local time
Yesterday, 20:00
Joined
Dec 1, 2011
Messages
93
OK, here you go...


Code:
Me.PALLET_QUANTITY = DLookup("[PALLET QTY]", "tblSupplierPalletQty", "[STOCK CODE]= '" & Forms![ENTER PURCHASE ORDER]![PRODUCT CODE] & "'" And "[SUPPLIER]='" & Forms![ENTER PURCHASE ORDER]![ACC NO] & "'")

Each of the criteria works on its own, it's probably a simple mistake!
 

VilaRestal

';drop database master;--
Local time
Today, 04:00
Joined
Jun 8, 2011
Messages
1,046
Perhaps do
Code:
Dim strWhere as String
strWhere = "[STOCK CODE]= '" & Forms![ENTER PURCHASE ORDER]![PRODUCT CODE] & "'" And "[SUPPLIER]='" & Forms![ENTER PURCHASE ORDER]![ACC NO] & "'"
debug.print strWhere
Me.PALLET_QUANTITY = DLookup("[PALLET QTY]", "tblSupplierPalletQty", strWhere)

so you can see in the immediate window what that where clause looks like.

You could then copy it and append it to a query
SELECT [PALLET QTY] FROM tblSupplierPalletQty WHERE
and see what access says about that query.
 

VilaRestal

';drop database master;--
Local time
Today, 04:00
Joined
Jun 8, 2011
Messages
1,046
In fact I can now see the error:

[PRODUCT CODE] & "'" And "[SUPPLIER]

should be

[PRODUCT CODE] & "' And [SUPPLIER]

(Access was trying to binary compare the two strings, getting false and using that false as the where of the dlookup)
 

sparks80

Physicist
Local time
Today, 04:00
Joined
Mar 31, 2012
Messages
223
Hi,

The AND part of the statement ended up outside the string, try this:

Code:
Me.PALLET_QUANTITY = DLookup("[PALLET QTY]", "tblSupplierPalletQty", "[STOCK CODE]='" & Forms![ENTER PURCHASE ORDER]![PRODUCT CODE] & "' And [SUPPLIER]='" & Forms![ENTER PURCHASE ORDER]![ACC NO] & "'")
 

rahulnagar

New member
Local time
Today, 08:30
Joined
Jul 2, 2012
Messages
1
Hi,
I am trying to copy data from one sheet to another depending on a certain data match. i am geeting error 438
below is the code
Private Sub CommandButton1_Click()

For x = 8 To 1500
Dim a As Integer
Dim b As String

Dim c As String

a = Sheets("New opportunity").Cells(x, 25)
b = Sheets("New opportunity").cell(x, 1)
If (a < 0) Then
c = b
End If
Sheets("status_report").cell(x, 1) = c




Next x


End Sub
 

Users who are viewing this thread

Top Bottom