Solved

Error with DLookup

Posted on 2014-11-09
6
164 Views
Last Modified: 2014-11-10
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?
0
Comment
Question by:SteveL13
  • 3
  • 3
6 Comments
 

Author Comment

by:SteveL13
ID: 40431361
By the way... LastName is text and may be null.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40431398
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
0
 

Author Comment

by:SteveL13
ID: 40432576
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

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40432590
I got it mixed up, sorry. Try this:

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

/gustav
0
 

Author Comment

by:SteveL13
ID: 40432606
Perfect!   Thanks again.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40432611
You are welcome!

/gustav
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question