Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookup Function

Status
Not open for further replies.

SHAWTY721

Programmer
Aug 16, 2007
116
US
I am receiving #Error in my unbound textbox where I am trying to use the DLookup Function to lookup the value that corresponds with "ADPCompany" and "Location Number" fields. Here is what my DLookup Function looks like:
' =DLookup("BranchNo","tblAllADPCoCodes","ADPCompany=" & Forms![frmMarthaPerPayPeriodDeduction]![ADPCompany])&","& DLookup("BranchNo","tblAllADPCoCodes","LocationNumber=" & Forms![frmMarthaPerPayPeriodDeduction]![LocationNo]) '

I'm not sure if I have the right syntax to include to things in the criteria.
 
I'm not sure if DLookups can be nested like that. Have you tried taking apart each of them to make sure they equate properly?

Could you morph this into a query and then execute the query via the dLookup?

Hope this helps.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
I believe the double quotes in the middle of your DLookup functions should be single quotes. I believe the following syntax is what you're looking for:
[tt]' =DLookup("BranchNo","tblAllADPCoCodes","ADPCompany=" & Forms![frmMarthaPerPayPeriodDeduction]![ADPCompany]) & ',' & DLookup("BranchNo","tblAllADPCoCodes","LocationNumber=" & Forms![frmMarthaPerPayPeriodDeduction]![LocationNo]) '
[/tt]

HTH,
Larry
 
I tried using the code above and "#Error" appears in the textbox.
 
This does not look logically correct nor syntaxtically correct unless you have a strange non normalized data structure.

you want to return a branch number where
ADPCompany = 'someCompany,BranchNumber'

Does ADPCompany data look like "MyCompany,1234"? If it really does that seems non-normalized. But if that is the case then I think:

"ADPCompany='" & Forms![frmMarthaPerPayPeriodDeduction]![ADPCompany]) & ',' & DLookup("BranchNo","tblAllADPCoCodes","LocationNumber=" & Forms![frmMarthaPerPayPeriodDeduction]![LocationNo]) & "'"

How should this really look?
"ADPCompany = '????'
 
How about...
Code:
=DLookup("BranchNo", "tblAllADPCoCodes", "ADPCompany = '" & Forms!frmMarthPerPayPeriodDedection!ADPCompany & "' AND LocationNumber = '" & Forms!frmMarthPerPayPeriodDeduction!LocationNo & "'")


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top