order of record listing in subforms - unexpected behavior

  • Thread starter Thread starter Nicholas Steinhoff
  • Start date Start date
N

Nicholas Steinhoff

I have a form that displays (let's say) a list of trips, that includes date
and city. It's based on a query that sorts by city and then by date. Now I
use this as a subform on a main form, which selects records based on a city
chosen on the form.

When I view it as a subform, the individual trips are no longer sorted by
date, but only by the order in which they were entered into the underlying
table. (My primary key sorts by date and then by city, so it isn't using the
key to sort.)

Is this behavior explainable? And more to the point, can I get the sorting
by date back easily in the subform? (I'm using Access 97, if this makes a
difference.)

Having just returned to doing Access development after a couple years away,
my apologies if this is a no-brainer.

Nicholas
 
Use the Open event of the subform to set its OrderBy property:

Private Sub Form_Open(Cancel As Integer)
Me.OrderBy = "MyDateField"
Me.OrderByOn = True
End Sub
 
Allen Browne said:
Use the Open event of the subform to set its OrderBy property:

Private Sub Form_Open(Cancel As Integer)
Me.OrderBy = "MyDateField"
Me.OrderByOn = True
End Sub

Thanks once again , Allen.

Can you tell me - is there an explainable reason why the sort order that is
applied when the subform is opened on its own isn't applied when it is
opened within its parent form? I'm trying to understand what's going on, and
maybe I can learn something fundamental about how Access operates.

Nicholas
 
Not sure this is explainable. It has to do with how and when Access uses the
index. Because part of the index is chewed up by the involvement of the
LinkMasterFields/LinkChildFields, the remaining part can't be used.

In general, if you need an order, the best idea is to specify one.
 
Back
Top