ACC: How to Use DLookup() to Look Up Values in Forms/Reports

Last reviewed: June 9, 1997
Article ID: Q93025
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

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

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, use one of these three techniques:

  • Use AutoLookup in forms.
  • Use multiple DLookup() functions in forms and reports. See the "More Information" section later in this article.
  • 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.

MORE INFORMATION

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("[LastName]", "Employees", "[EmployeeID] =_
            Forms![FormName]![ControlName]")

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("[Last Name]", "Employees", "[Employee ID] =_
            Forms![FormName]![ControlName]")

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.

REFERENCES

For more information about the DLookup() function, search the Help Index for "DLookup," or ask the Microsoft Access 97 Office Assistant.


Additional query words: functions
Keywords : FmsHowto kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 9, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.