Query Expression using DLookUp

  • Thread starter Thread starter Wei
  • Start date Start date
W

Wei

The following expression returns "#Error", can anyone
please tell me why?

CL: IIf([VEH_YEAR]=2003,DLookUp("[2003CL]","vrg-
mce","[Vehicle_Code]=" & [VEH_CODE]),"do something else")

"vrg-mce" is a table that contains fields like
Vehicle_Code, 2003CL, etc.

I think the problem is in here:"[Vehicle_Code]=" &
[VEH_CODE]. But I don't know how to fix it.

Thanks for any help.

Wei
 
If VEH_CODE is a Text type field, try:

CL: IIf([VEH_YEAR] = 2003,
DLookUp("[2003CL]","vrg-mce","[Vehicle_Code] = """ & [VEH_CODE] & """"),
"do something else")


If it is a Number type field, you need to consider the case where VEH_CODE
is Null, and therefore the 3rd argument would equate to just:
[Vehicle_Code] =

To prevent that:

CL: IIf([VEH_YEAR] = 2003,
DLookUp("[2003CL]","vrg-mce","[Vehicle_Code] = " Nz([VEH_CODE], 0)),
"do something else")
 
Hi,


The table name is illegal as a table name. You may try to use [ ] around
it:

"[vgr-mce]"


(second argument of your DLookup).



If the vehicle code is some text, you may try:

"Vehicle_Code=""" & VEH_CODE & """"
1 3 4


as third argument. The numbers under the line are not part of the code, they
just show the number of involved double-quote.



Hoping it may help,
Vanderghast, Access MVP
 
Yes, thank you so much, Vanderghast! It worked!

But why do I need to put so many quotation marks? Thanks a
lot if you could explain it to me, so that I don't make
the same mistake again.

Wei
-----Original Message-----
Hi,


The table name is illegal as a table name. You may try to use [ ] around
it:

"[vgr-mce]"


(second argument of your DLookup).



If the vehicle code is some text, you may try:

"Vehicle_Code=""" & VEH_CODE & """"
1 3 4


as third argument. The numbers under the line are not part of the code, they
just show the number of involved double-quote.



Hoping it may help,
Vanderghast, Access MVP


The following expression returns "#Error", can anyone
please tell me why?

CL: IIf([VEH_YEAR]=2003,DLookUp("[2003CL]","vrg-
mce","[Vehicle_Code]=" & [VEH_CODE]),"do something else")

"vrg-mce" is a table that contains fields like
Vehicle_Code, 2003CL, etc.

I think the problem is in here:"[Vehicle_Code]=" &
[VEH_CODE]. But I don't know how to fix it.

Thanks for any help.

Wei


.
 
Thanks Allen!

Wei

-----Original Message-----
If VEH_CODE is a Text type field, try:

CL: IIf([VEH_YEAR] = 2003,
DLookUp("[2003CL]","vrg-mce","[Vehicle_Code] = """ & [VEH_CODE] & """"),
"do something else")


If it is a Number type field, you need to consider the case where VEH_CODE
is Null, and therefore the 3rd argument would equate to just:
[Vehicle_Code] =

To prevent that:

CL: IIf([VEH_YEAR] = 2003,
DLookUp("[2003CL]","vrg-mce","[Vehicle_Code] = " Nz ([VEH_CODE], 0)),
"do something else")

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

The following expression returns "#Error", can anyone
please tell me why?

CL: IIf([VEH_YEAR]=2003,DLookUp("[2003CL]","vrg-
mce","[Vehicle_Code]=" & [VEH_CODE]),"do something else")

"vrg-mce" is a table that contains fields like
Vehicle_Code, 2003CL, etc.

I think the problem is in here:"[Vehicle_Code]=" &
[VEH_CODE]. But I don't know how to fix it.

Thanks for any help.

Wei


.
 
Back
Top