Solved

Error with DLookup

Posted on 2014-11-09
6
159 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now