Nesting DLOOKUPs

G

GD

Can I nest a DLOOKUP within another DLOOKUP expression? I've tried:

=DLookUp("[tblEMPLOYEE]![NAME]","tblEMPLOYEE","[tblEMPLOYEE]![EMPLOYEE]='" &
DLookUp("[tblDMLOG]![EMPNO]","tblDMLOG","[tblDMLOG]![DM#]='" &
Forms!frmGregTest!Text40 & "'"))

The 2nd DLOOKUP is getting the employee # from tblDMLOG, and I want to use
that to get the employee name from tblEMPLOYEE. The 2nd one works by itself.
What is wrong with my expression?

Thanks for your invaluable time!!
 
D

Dale Fye

I think you are missing an extra set of closing quotes. Try:

=DLookUp("[NAME]", "tblEMPLOYEE", "[EMPLOYEE]='" & DLookUp("[EMPNO]",
"tblDMLOG", "[DM#]='" & Forms!frmGregTest!Text40 & "'") & "'")


--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
G

GD

I'm still having trouble. If EMPNO is a number, how should it look? The
others should be text.
--
GD


Dale Fye said:
I think you are missing an extra set of closing quotes. Try:

=DLookUp("[NAME]", "tblEMPLOYEE", "[EMPLOYEE]='" & DLookUp("[EMPNO]",
"tblDMLOG", "[DM#]='" & Forms!frmGregTest!Text40 & "'") & "'")


--
HTH
Dale

email address is invalid
Please reply to newsgroup only.



GD said:
Can I nest a DLOOKUP within another DLOOKUP expression? I've tried:

=DLookUp("[tblEMPLOYEE]![NAME]","tblEMPLOYEE","[tblEMPLOYEE]![EMPLOYEE]='" &
DLookUp("[tblDMLOG]![EMPNO]","tblDMLOG","[tblDMLOG]![DM#]='" &
Forms!frmGregTest!Text40 & "'"))

The 2nd DLOOKUP is getting the employee # from tblDMLOG, and I want to use
that to get the employee name from tblEMPLOYEE. The 2nd one works by itself.
What is wrong with my expression?

Thanks for your invaluable time!!
 
G

GD

We're almost there, Chris =)

The following gets me what I need when there's an entry in Text40:

=DLookUp("[NAME]","tblEMPLOYEE","[EMP#]=" &
DLookUp("[EMPNO]","tblDMLOG","[DM#]='" & Forms!frmGregTest!Text40 & "'"))

My problem now is that #Error appears when Text40 is blank. Can I fix that?

--
GD


Chris O'C via AccessMonster.com said:
=DLookup("[NAME]", "tblEMPLOYEE", "EMPLOYEE='" _
& DLookup("EMPNO", "tblDMLOG", "[DM#]=" & Forms!frmGregTest!Text40) _
& "'")

Chris

I'm still having trouble. If EMPNO is a number, how should it look? The
others should be text.
 
D

Dirk Goldgar

GD said:
We're almost there, Chris =)

The following gets me what I need when there's an entry in Text40:

=DLookUp("[NAME]","tblEMPLOYEE","[EMP#]=" &
DLookUp("[EMPNO]","tblDMLOG","[DM#]='" & Forms!frmGregTest!Text40 & "'"))

My problem now is that #Error appears when Text40 is blank. Can I fix
that?


I suspect that this would work for you:

=DLookUp("[NAME]","tblEMPLOYEE","[EMP#]=" &
DLookUp("[EMPNO]","tblDMLOG","[DM#]=[Forms]![frmGregTest]![Text40]"))

That expression was wrapped to two lines for posting, but it should all be
on one line in practice.

I believe the DLookup function will evaluate form/control references
embedded in the criteria. If I'm wrong, let me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top