Is it okay to put sort code upon 'form open'?

S

StargateFan

I just want to check with the group. I found this reference to the
subject here:
http://groups.google.ca/group/micro...7?q=sort+on+form+open&rnum=1#adc3d476569bced7
and it seems that best thing to do is to use a query for a form. But
it's daunting as I have a highly fine-tuned main form already and
couldn't figure out how to change easily without rebuilding form.

In the meantime, I did figure out how to use the code provided at
bottom of above message (which I put in the "on open" box in the
properties of the form):

Private Sub Form_Open(Cancel As Integer)
Me.OrderBy = "Contacts.Last"
End Sub

You that are experts here, is it alright to use that in this type of
situation? I will be paying more attention in future to building even
my main form on a query first, but if I do find I'm in this sort of
jam in future, would like to know if there are inherent problems using
this "OrderBy" approach esp. as DBs get larger with data over time.

Thanks. :eek:D
 
R

Rick Brandt

StargateFan said:
I just want to check with the group. I found this reference to the
subject here:
http://groups.google.ca/group/micro...7?q=sort+on+form+open&rnum=1#adc3d476569bced7
and it seems that best thing to do is to use a query for a form. But
it's daunting as I have a highly fine-tuned main form already and
couldn't figure out how to change easily without rebuilding form.

All you need to do for this is change the RecordSource from...

TableName
....to...
SELECT * FROM TableName ORDER BY SomeField

This will not impact the way your form works at all.
In the meantime, I did figure out how to use the code provided at
bottom of above message (which I put in the "on open" box in the
properties of the form):

Private Sub Form_Open(Cancel As Integer)
Me.OrderBy = "Contacts.Last"
End Sub

You that are experts here, is it alright to use that in this type of
situation? I will be paying more attention in future to building even
my main form on a query first, but if I do find I'm in this sort of
jam in future, would like to know if there are inherent problems using
this "OrderBy" approach esp. as DBs get larger with data over time.

It should be fine but you also need to set OrderByOn = True or nothing will
happen.

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