Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sorting records via index on subform (2003)

    I have a form with a tabular suborm, which I would like to de sorted by the index, but putting an index name in the form's OrderBy property does not seem to work for me. I've not been able to find any relevant documentation to help me out *


    Here's a little bit on my situation. I'm writing a small office vacationtracking program. The main form is the employee record, with EmplyeeNumber etc. The subform has records for the amount of vacation taken each month. This table has a year field, and a Month field.

    I want to link to the monthly vacation records sub form by Employee Number and sorted by Year desceninding and Month descending. I have an Index on the table sorted this way, and I have tried to explicitly put in the srt order in the OrderBy property, but neither is sorting the records at all.

    Obviously, I'm missing something here. Can anyone give me a bit of guidance as to what it might be?

    Jim

    * "Sort Records Subform" in Help gets me results on sorting records, and making subforms, but not sorting records in subforms <sigh>

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting records via index on subform (2003)

    Instead of using the sort property of the subform, you should better use a query as record source of the subform and set the sorting in this query.
    Francois

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Sorting records via index on subform (2003)

    The easiest solution is to create a query based on the table behind the subform, and to specify the sort order in this query. Set the Record Source property of the subform to the name of the query instead of the name of the table.

  4. #4
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting records via index on subform (2003)

    Thank you Francois and Hans,

    That works wonderfully.

    2 things still bother me, but it's merely academic curiousity.

    - Why doesn't the Ordeby work as I expected. or in my case, apparently not at all?

    - I sorted on [EmployeeNum]Ascending, [Year] descending and [Month] Descending. In my case, they are sorted in the desired order for my project. Why? Is it based on the order the fields apear in the Query grid?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Sorting records via index on subform (2003)

    To apply the OrderBy property, you also have to set the OrderByOn property to True. This can only be done in Visual Basic. This can be very handy if you need to turn the sort order on or off while the form is open, or if you need to change the sort order. But if you want a fixed sort order, it is much easier to set it in a query.

    The sort order of a query is determined by the order of the fields in the query grid: the records are sorted on the leftmost field that has a sort order specified, then on the next field etc.

  6. #6
    5 Star Lounger
    Join Date
    May 2003
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    629
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting records via index on subform (2003)

    Thanks for your help, I guess that explains why serveral hours playihng with the form didn't yield any useful results <img src=/S/disappointed.gif border=0 alt=disappointed width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •