Dlookup fails in Calculated field

Keith

Registered User.
Local time
Today, 02:31
Joined
May 21, 2000
Messages
129
I have the following code in a calculated field in a query which is the record source for a form.

Code:
Test: IIf(IsNull([NatSubsBranch]),"",IIf([NatSubsBranch]=1,"Standing Order",IIf([NatSubsBranch]=_
[BranchID],"",DLookUp("Branch_Name","tblBranch","BranchID=NatSubsBranch"))))

When I run the query I get an error 'Access cannot find the field NatSubsBranch'. I have tested each part of the code and it's failing on the Dlookup part.

However if I insert the following code as the record source of an unbound text box on the form I get the correct result. Can anybody tell me why please?

Code:
=IIf(IsNull([NatSubsBranch]),"",IIf([NatSubsBranch]=1,"Standing Order",IIf([NatSubsBranch]=_
[BranchID],"",DLookUp("Branch_Name","tblBranch","BranchID=NatSubsBranch"))))
 
Hi

Try this:

Test: IIf(IsNull([NatSubsBranch]),"",IIf([NatSubsBranch]=1,"Standing Order",IIf([NatSubsBranch]=_
[BranchID],"",DLookUp("Branch_Name","tblBranch","BranchID=" & [NatSubsBranch]))))
 
Thanks Ari, that did the trick.
 

Users who are viewing this thread

Back
Top Bottom