Sorting Finding Filtering records in a Recordset

The Recordset object has various properties and methods that allow you to sort, filter, and find records. Some examples of these properties will now be discussed.

The Sort Property

The Sort property allows you to modify the order that the records appear in the recordset.

Try It Out Sorting Records for the Unbound Contacts Form

Look at an example of how to sort the rsContacts recordset that you used previously.

1. In the code for the Form_Load event procedure of frmContactsUnbound, immediately following the line setting the ActiveConnection property, add the following Sort command:

With rsContacts

'specify a cursortype and lock type that will allow updates .CursorType = adOpenKeyset .CursorLocation = adUseClient .LockType = adLockBatchOptimistic

'open the recordset based on tblContacts table using the existing connection .Open "tblContacts", cnCh5 'disconnect the recordset .ActiveConnection = Nothing

'sort the recordset

.Sort = "txtLastName, txtFirstName, txtMiddleName"

End With

2. Now re-open the form and navigate through records.

0 0

Post a comment