It is always best to qualify your objects. Since CORP_ITEM_CD is a numer
field, you need to look it up with a numeric value. Here is what I would
recommend:
=nz(DLookUp("[UPC_SALES]","SQLDAT3_SSITMXRF","[CORP_ITEM_CD] = " &
CLng(Me.tblItemNumber)),0)
That strips the leading zeros off and converts it to a Long data type to
match CORP_ITEM_CD
--
Dave Hargis, Microsoft Access MVP
:
UPC_SALES is the UPC number field
SQLDAT3_SSITMXRF is the database table
CORP_ITEM_CD is the item number that links to the UPC_SALES
tblItemNumber is the text box where I input the item number.
=nz(DLookUp("[UPC_SALES]","SQLDAT3_SSITMXRF","[CORP_ITEM_CD] = " &
[tblItemNumber]),0)
is the textbox that populates the UPC_SALES number.
No, you wouldn't do either or those.
What is [tblItemNumber]?
Is it a control on your form, or what?
Let me know and I can show you the correct syntax.
--
Dave Hargis, Microsoft Access MVP
:
crop_item_cd is a numeric data type. so with your formula below would
I do this
=nz(DLookUp(Format("[UPC_SALES]","00000"),"SQLDAT3_SSITMXRF","[CORP_ITEM_CD]
= " &
[tblItemNumber]),0)
or do what the gentleman above wrote
=nz(DLookUp(RIGHT$("00000" & "[UPC_SALES]",
5),"SQLDAT3_SSITMXRF","[CORP_ITEM_CD] = " &
[tblItemNumber]),0)
What data type is [CORP_ITEM_CD]?
As written, you code is expecting a numeric data type. Therefore, there
would be no leading zeros. Numbers don't have leading zeros. You can
present them to the user that way using the Format function. For example to
get a string 5 characters long with leading zeros, it would be:
=Format(127,"00000")
--
Dave Hargis, Microsoft Access MVP
:
I have this code
=nz(DLookUp("[UPC_SALES]","SQLDAT3_SSITMXRF","[CORP_ITEM_CD] = " &
[tblItemNumber]),0)
this works properly but i need to be in number format. right now this
pulls the entry "3", but can it be in this format "00003". Also if i
pull another record that is "127" could it show as "00127", I need 0's
to fill the slots where the number doesn't, make sense. Thanks.
Ryan