Export (0) Print
Expand All
Expand Minimize

Application.DFirst Method

Office 2007
You can use the DFirst function to return a random record from a particular field in a table or query when you simply need any value from that field. .

Syntax

expression.DFirst(Expr, Domain, Criteria)

expression   A variable that represents an Application object.

Parameters

NameRequired/OptionalData TypeDescription
ExprRequiredStringAn expression that identifies the field from which you want to find the first or last value. It can be either a string expression identifying a field in a table or query, or 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.
DomainRequiredStringA string expression identifying the set of records that constitutes the domain.
CriteriaOptionalVariantAn optional string expression used to restrict the range of data on which the DFirst function is performed. For example, criteria is often equivalent to the WHERE clause in an SQL expression, without the wrd WHERE. If criteria is omitted, the DFirst function evaluates expr against the entire domain. Any field that is included in criteria must also be a field in domain; otherwise, the DFirst function returns a Null.

Return Value
Variant

Remarks

Bb148911.vs_note(en-us,office.12).gif  Note
If you want to return the first or last record in a set of records (a domain), you should create a query sorted as either ascending or descending and set the TopValues property to 1. From Visual Basic, you can also create an ADO Recordset object and use the MoveFirst or MoveLast method to return the first or last record in a set of records.

See Also


Community Additions

ADD
Show:
© 2015 Microsoft