I guess you could wrap the second DLookup in the Nz function, with a
Value
If Null that is meaningless. The general idea is to construct the second
DLookup so that it returns some sort of value. If there are no records
that
match the criteria the expression evaluates to Null, but since you are
using
that value in the first criteria expression you have:
=DLookUp("ContactName","tbl_Contacts","ContactID = " & Null
Maybe something like:
Nz(DLookUp("ContactID","tbl_ContactProject","RoleID = 1 AND ProjectID = "
&
[Forms]![frm_Projects]![ProjectID]),"999999999")
If the second DLookup returns null then 999999999 is substituted, so the
first DLookup becomes:
=DLookUp("ContactName","tbl_Contacts","ContactID = 999999999")
As long as there is no contact with ID 999999999 the expression will
evaluate to Null, and the text box will be blank. If you need something
to
appear in that text box you can wrap the first DLookup in the Nz
function.
I think you would do better to use a query that includes both tables, as
I
suggested in another post.
MeSteve said:
This is what is semming to work:
=DLookUp("ContactName","tbl_Contacts","ContactID = " &
DLookUp("ContactID","tbl_ContactProject","RoleID = 1 AND ProjectID = "
&
[Forms]![frm_Projects]![ProjectID]))
One more thing, how do I prevent getting an error if the value is Null?
:
RoleID is a number, but not on tbl_Contacts, that is my problem (I
think).
RoleID is on tbl_ContactProject and tbl_Roles
:
Is RoleID a number field in tbl_Contacts? What happens if you use
"RoleID =
1" as the sole criteria?
Yes, and it returns Error#
=DLookUp("ContactName","tbl_Contacts","ContactID = " &
Forms!frm_Projects!subfrm_ProjectManagers.Form!ContactID & " AND
RoleID =
1")
:
Have you tested that? It looks as if it would work, as long as
RoleID is
a
number. You may need a space after the double quote and before
the
AND
("
AND), but I think it would work as is.
What would be the proper sytax for this:
=DLookUp("ContactName","tbl_Contacts","ContactID = " &
Forms!frm_Projects!subfrm_ProjectManagers.Form!ContactID & "AND
RoleID
=
1")
Or can I even do that?
:
If you count your quotes and parens and square brackets they
should
all
be
even numbers. You are missing a quote. Try:
=DLookUp("ContactName","tbl_Contacts", "ContactID = " &
Forms![frm_Projects]![subfrm_ProjectManagers].Form![ContactID]
)
If ContactID is text/string, try:
=DLookUp("ContactName","tbl_Contacts", "ContactID = """ &
Forms![frm_Projects]![subfrm_ProjectManagers].Form![ContactID]
&
"""")
--
Duane Hookom
Microsoft Access MVP
:
I am trying to put this:
=DLookUp("ContactName","tbl_Contacts", "ContactID =
Forms![frm_Projects]![subfrm_ProjectManagers].Form![ContactID]
)
as a control source on a form. I get an error stating that
a
string
can be
up to 2048 characters..., but this is only 118 characters.
What is
happening?