The following example returns the average freight cost for orders shipped to the United Kingdom on or after January 1, 1996. The domain is an Orders table. The criteria argument restricts the resulting set of records to those for which ShipCountry equals UK and ShippedDate is greater than or equal to 1-1-96. Note that the keyword AND is included in the string to separate the multiple fields in the criteria argument. All records included in the DAvg function calculation will have both of these criteria.
Dim dblX As Double
dblX = DAvg("[Freight]", "Orders", _
"[ShipCountry] = 'UK' AND [ShippedDate] >= #1-1-96#")
The next example calculates an average by using a variable, strCountry
, in the criteria argument. Note that single quotation marks (') are included in the string expressions, so that when all of the strings are concatenated, the string literal UK
will be enclosed in single quotation marks. In this example, the keyword OR is used to separate the multiple fields. This example will return all records that have either or both criteria.
Dim dblX As Double, strCountry As String
strCountry = "UK"
dblX = DAvg("[Freight]", "Orders", _
"[ShipCountry] = '" & strCountry & "'OR _
[ShippedDate] >= #1-1-96#")