[AccessD] Basic Unbound Form with Classes and Collections Part 3.

DWUTKA at marlow.com DWUTKA at marlow.com
Fri Jun 9 15:02:05 CDT 2006


Right now, our frmPeople should open, but nothing happens when we click our
next/previous buttons, nor when we change the sort order option group.  So
let's put the code in for those.  The following is the code for the 'On
Click' events for all three of those controls:

Private Sub SortOrder_Click()
DisplayPerson
End Sub

Private Sub cmdNextRecord_Click()
Select Case Me.SortOrder.Value
    Case 1
        Set CurrentPerson =
PeopleClass.PersonByFirstName(CurrentPerson.FirstSortOrder + 1)
    Case 2
        Set CurrentPerson =
PeopleClass.PersonByLastName(CurrentPerson.LastSortOrder + 1)
End Select
DisplayPerson
End Sub

Private Sub cmdPreviousRecord_Click()
Select Case Me.SortOrder.Value
    Case 1
        Set CurrentPerson =
PeopleClass.PersonByFirstName(CurrentPerson.FirstSortOrder - 1)
    Case 2
        Set CurrentPerson =
PeopleClass.PersonByLastName(CurrentPerson.LastSortOrder - 1)
End Select
DisplayPerson
End Sub

Okay, now let's test our form.  Open it.  First name should be Charlotte
Foust, because it should default to sorting by first name.  Clicking the
next button (because the previous button should be disabled by the
DisplayPerson routine) will let us click our way through our list of people.
As we click away, we should see what record we are on in our label.  Once we
reach the end, the next button is disabled.  We can click backwards too.
Now if we switch the sort order, none of the data changes, but the Record x
of y should show us a new position in the recordset, and moving back and
forth in there will go by the new sort order.

Have it sort by First Name, and go to the 3rd of 9 (my name).  Switch the
sort order.  Notice that it now shows 9 or 9 and also disables the Next
button?  That is because all of the displaying and controlling functions are
in DisplayPerson, and the controls that are moving things around are
triggering that function once they do their initial purpose.  ie, in the
Next and Previous buttons, we are setting the CurrentPerson object to a new
person (based on the current sort order, and the position the old reference
is currently in).  For the changing of the sort order, the applicable value
is already changed, so we just run the DisplayPerson function.

I will send one last email on the Basic process.  I will sum up a few
things, point out key things we've done.

Drew



More information about the AccessD mailing list