Ordering records for display

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form in an application in which I need to have the records displayed
so the most recent one comes up when the form is opened (during the Load
event). This worked fine until I changed the form to set it's focus on a
combo box when it opened. I checked the table behind the form and noticed
that the data is sorted in descending order - if I resort the table and try
to open the form again I still get the same result as before. Resorting the
data behind the form doesn't seem to matter.
Do you have any suggestions for correcting this situation?
 
Hi, Dave.
I checked the table behind the form and noticed
that the data is sorted in descending order - if I resort the table and try
to open the form again I still get the same result as before. Resorting the
data behind the form doesn't seem to matter.

The records are retrieved from the table in no particular order unless one
uses a query and identifies a sort order for one or more fields. Create a
query that returns all fields and uses the field that can identify the most
recent record (perhaps OrderDate?) for the sort order -- descending, of
course -- then base the form's record source on that query, not the table.
You won't need to program anything in the form's OnLoad( ) event, because
the records will automatically be sorted when the form opens, with the most
recent record displayed first.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
That may be easier said than done. The form that displays the data is a
tabbed form - each tab pulls data from different tables in the application
but they are all related either through a direct link with a key field or
through a junction table.
 
Hi, Dave.

Presumably each of those tabs is displaying one or more subforms with the
related records from the other tables. Each subform's record source can be
a sorted query, too, but it may not be possible to sort using the most
recent records first unless there's a date/time field in each of these
tables.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 
Back
Top