Avatar of SteveL13
SteveL13
Flag for United States of America asked on

Error with DLookup

I am getting a #Error using a DLookup on a report..

Here is the control source for the field:

=DLookUp("[LastName]","tblEmployees","[ID] = " & [Reports]![rptOpenServiceEvents]![txtTechnician5])

How can I change this to the #Error goes away?
Microsoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
SteveL13

ASKER
By the way... LastName is text and may be null.
Gustav Brock

It should read:

Dim lngID As Long
lngID = Nz([Reports]![rptOpenServiceEvents]![txtTechnician5], 0)
=DLookUp("[LastName]","tblEmployees","[ID] = " & lngID & "")

Of course, if rptOpenServiceEvents is not open, it will fail.

/gustav
SteveL13

ASKER
Am getting invalid use of null with this solution.

Here is what I have which is a copy/paste in the onprint event of the detail section of the report...

    Dim lngID As Long
    lngID = Nz([Reports]![rptOpenServiceEvents]![txtTechnician5], 0) = DLookup("[LastName]", "tblEmployees", "[ID] = " & lngID & "")

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Gustav Brock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SteveL13

ASKER
Perfect!   Thanks again.
Gustav Brock

You are welcome!

/gustav