Article ID: 109380
Article Last Modified on 5/6/2003
DFirst and DLast return values from the first and last occurrence according to the order of records in domain. If domain is an indexed table, the order follows the current index. Otherwise, the order follows the actual order of the records.
Option Explicit
Function GetFirst (Expr$, Domain$, Criteria$)
Dim MyDB As Database
Dim MyDyna As Dynaset
On Error GoTo Err_GetFirst
Set MyDB = CurrentDB()
Set MyDyna = MyDB.CreateDynaset(Domain$)
If Len(Criteria$) > 0 Then
MyDyna.Filter = Criteria$
Set MyDyna = MyDyna.CreateDynaset()
End If
MyDyna.MoveFirst
GetFirst = MyDyna(Expr$)
Bye_GetFirst:
Exit Function
Err_GetFirst:
GetFirst = Null
Resume Bye_GetFirst
End Function
Function GetLast (Expr$, Domain$, Criteria$)
Dim MyDB As Database
Dim MyDyna As Dynaset
On Error GoTo Err_GetLast
Set MyDB = CurrentDB()
Set MyDyna = MyDB.CreateDynaset(Domain$)
If Len(Criteria$) > 0 Then
MyDyna.Filter = Criteria$
Set MyDyna = MyDyna.CreateDynaset()
End If
MyDyna.MoveLast
GetLast = MyDyna(Expr$)
Bye_GetLast:
Exit Function
Err_GetLast:
GetLast = Null
Resume Bye_GetLast
End Function
Keywords: kbusage KB109380