Microsoft KB Archive/93025

= ACC: How to Use DLookup to Look Up Values in Forms or Reports =

Article ID: 93025

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q93025



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
You can display multiple fields in a combo or list box on a form or report even when those fields come from a table that is not bound to the form or report. You can also update controls, such as text boxes, with new information based on what a user selects from a combo or list box.

To accomplish these objectives, you can use one of the following techniques:


 * Use AutoLookup in forms.
 * Use multiple DLookup functions in forms and reports.
 * Use the Column property of a multiple-column combo box to update a text box control with new information as focus moves from row to row in the combo box.

This article shows you how to use the DLookup function to look up values in forms or reports.



DLookup Function
The syntax for the DLookup function is a follows:

  DLookup(expr, domain, [criteria])

The DLookup function returns a value from a field in a specified set of records called the domain. The DLookup function specifies the criteria for the domain. To make the domain dependent on one or more values listed in controls on a form or report, refer to the controls in the DLookup criteria argument.

The following example looks in the Employees table (the domain) and returns the Last Name of the Employee ID specified in the [ControlName] control on the Form.

In Microsoft Access 7.0 and 97
  =DLookup(&quot;[LastName]&quot;, &quot;Employees&quot;, &quot;[EmployeeID] =_            Forms![FormName]![ControlName]&quot;)

In Microsoft Access 1.x and 2.0
NOTE: In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

  =DLookup(&quot;[Last Name]&quot;, &quot;Employees&quot;, &quot;[Employee ID] =_            Forms![FormName]![ControlName]&quot;)

For reports, use Reports![ReportName]![ControlName].

DLookup returns one value from a single field even if more than one record satisfies the criteria. If no record satisfies the criteria or if the domain contains no records, DLookup returns Null.

