Access VBA Macro Programming

(Joao Candeias) #1
FindLast
TheFindLastmethod uses a specified criterion to find the last instance of a record within the
recordset. The recordset must be opened as a snapshot or dynaset (which is updatable) for the
method to work:

Dim RecSet As Recordset
Set RecSet = CurrentDb.OpenRecordset("MyTable", dbOpenDynaset)
RecSet.FindLast ("MyField='Data'")
MsgBox RecSet!MyField
RecSet.close
Set RecSet=Nothing

This code will move to the last record where the field MyField contains the value Data.

FindNext
TheFindNextmethod uses a specified criterion to find the next instance of a record within
the recordset. The recordset must be opened as a snapshot or dynaset (which is updatable)
for the method to work:

Dim RecSet As Recordset
Set RecSet = CurrentDb.OpenRecordset("MyTable", dbOpenDynaset)
RecSet.FindNext ("MyField='Data'")
MsgBox RecSet!MyField
RecSet.close
Set RecSet=Nothing

This code will move to the next record where the field MyField contains the value Data. If
the recordset is still at the first record, this will return the same results as aFindFirstmethod.

FindPrevious
TheFindPreviousmethod uses a specified criterion to find the previous instance of a record
within the recordset. The recordset must be opened as a snapshot or dynaset (which is
updatable) for the method to work:

Dim RecSet As Recordset
Set RecSet = CurrentDb.OpenRecordset("MyTable", dbOpenDynaset)
RecSet.FindPrevious ("MyField='Data'")
MsgBox RecSet!MyField
RecSet.close
Set RecSet=Nothing

This code will move to the previous record where the field MyField contains the value
Data. If the recordset is at the last record, this will return the same results as aFindLast
method.

210 Microsoft Access 2010 VBA Macro Programming

Free download pdf