Vous êtes sur la page 1sur 2

You can use the DLookup function to get the value of a particular field from a

specified set of records (a domain). Use the DLookup function in a Visual Basic for
Applications (VBA) module, a macro, a query expression, or a calculated control on a
form or report.
You can use the DLookup function to display the value of a field that isn't in the
record source for your form or report. For example, suppose you have a form based
on an Order Details table. The form displays the OrderID, ProductID, UnitPrice,
Quantity, and Discount fields. However, the ProductName field is in another table,
the Products table. You could use the DLookup function in a calculated control to
display the ProductName on the same form.
Syntax
DLookup(expr, domain [, criteria] )
The DLookup function syntax has these arguments:
ARGUMENT DESCRIPTION
expr Required. An expression that identifies the field whose value you want
to return. It can be a string expression identifying a field in a table or
query, or it can be an expression that performs a calculation on data in
that field. In expr, you can include the name of a field in a table, a
control on a form, a constant, or a function. If expr includes a function,
it can be either built-in or user-defined, but not another domain
aggregate or SQL aggregate function.
domain Required. A string expression identifying the set of records that
constitutes the domain. It can be a table name or a query name for a
query that does not require a parameter.
criteria Optional. A string expression used to restrict the range of data on which
the DLookup function is performed. For example, criteria is often
equivalent to the WHERE clause in an SQL expression, without the
word WHERE. If criteria is omitted, the DLookup function evaluates
expr against the entire domain. Any field that is included in criteria
must also be a field in domain; otherwise, the DLookup function
returns a Null.
TIP In Access 2010, the Expression Buil der has IntelliSense, so you
can see what arguments your expression requires.
Watch a video or try Office 2010.
Remarks
The DLookup function returns a single field value based on the information specified
in criteria. Although criteria is an optional argument, if you don't supply a value for
criteria, the DLookup function returns a random value in the domain.
If no record satisfies criteria or if domain contains no records, the DLookup
function returns a Null.
If more than one field meets criteria, the DLookup function returns the first
occurrence. You should specify criteria that will ensure that the field value returned
by the DLookup function is unique. You may want to use a primary key value for
your criteria, such as [EmployeeID] in the following example, to ensure that the
DLookup function returns a unique value:
Dim varX As Variant
varX = DLookup("[LastName]", "Employees", _
"[EmployeeID] = 1")

Whether you use the DLookup function in a macro or module, a query expression,
or a calculated control, you must construct the criteria argument carefully to ensure
that it will be evaluated correctly.
DLookup Function
Applies to: Microsoft Office Access 2007
Support / Access / Macros and programmability / Functions (alphabetical)
DLookup Function - Access - Microsoft Office http://office.microsoft.com/en-us/access-help/dlookup-function-HA0...
1 of 2 14/01/11 4:11 PM
2011 Microsoft Corporation. All rights reserved.


DLookup Function - Access - Microsoft Office http://office.microsoft.com/en-us/access-help/dlookup-function-HA0...
2 of 2 14/01/11 4:11 PM

Vous aimerez peut-être aussi