Solved

Error with DLookup

Posted on 2014-11-09
6
165 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

831 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