Access: DFirst Function
In Access, the DFirst function returns the first value from a specified set of records (or domain).
The syntax for the DFirst function is:
DFirst ( expression, domain, [criteria] )
expression is the field from which you want the first value.
domain is the set of records. This can be a table or a query name.
criteria is optional. It is the WHERE clause to apply to the domain.
For example:
Let's take a look at a simple example:
DFirst("UnitPrice", "Order Details", "OrderID = 10248")
In this example, you would retrieve the first UnitPrice value in the Order Details table where the OrderID is 10248.
VBA Code
The DFirst function can be used in VBA code. For example:
Dim LTotal As Currency
LTotal = DFirst("UnitPrice", "Order Details", "OrderID = 10248")
In this example, the variable called LTotal would now contain the first UnitPrice from the Order Details table where the OrderID is 10248.
SQL/Queries
You can also use the DFirst function in a query.
