Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    May 2001
    Location
    Germany
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OrderBy property in a subform

    Hallo,

    I have an Access 97 application where the form "SF_PosData" is a subform in another form ("MF_Orders").
    Users should be able to sort the subform data with the respective buttons on the icon bar.
    But I want all such sorts to be removed, when the form / subform is unloaded. I thought, the OrderBy property of the "SF_PosData" form would be the right place to achieve this.
    I tried the following Code for the form "SF_Pos_Data", but it does not seem to do the job

    Private Sub Form_Unload(Cancel As Integer)
    Me.OrderBy = ""
    End Sub

    Any ideas??

    Thanks a lot
    Doris

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OrderBy property in a subform

    Don't forget the OrderByOn property. You may want to set that to False.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  3. #3
    Lounger
    Join Date
    May 2001
    Location
    Germany
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OrderBy property in a subform

    I thought about that, too, an I think it might help.
    Although I would rather have nothing left in the OrderBy property itself.

    The problem with both solutions is, that I seem to miss the right place for applying them.
    I tried both the Form_Close and the Form-Unload event of the form which is the subform. I tried above mentioned code and I tried the following

    Private Sub Form_Close()
    OrderByOn = False
    End Sub

    But when I reopen the form, it is sorted as it was before closing. I seem to be doing something wrong, and I cannot figure out what it is.

    Thanks
    Doris

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OrderBy property in a subform

    I may be mistaken (and indeed may have been mistaken earlier), but doesn't the sorting done on a form get stored with its recordsource (table or query)? In which case, maybe you should actually set an order using OnOpen or OnLoad events. If you have an autonumber field or some field other field that shows the natural order, you can order the form by that field.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  5. #5
    Lounger
    Join Date
    May 2001
    Location
    Germany
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OrderBy property in a subform

    As far as I understood the online help, the sorting is not stored in the recordsource but in a property of the form itself (the property OrderBy).
    But you are perfectly right that I should use the OnOpen or OnLoad event (instead of the OnUnload event). Now, I sat the OrderByOn property to False in an OnLoad Statement, and this worked wonders.

    Private Sub Form_Load()
    OrderByOn = False
    End Sub

    What does not work, however, is when I try the same with the OrderBy property. As for example in

    Private Sub Form_Load()

  6. #6
    Lounger
    Join Date
    Apr 2001
    Location
    Stuttgart, Germany
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: OrderBy property in a subform

    Doris,

    if you want to set the OrderBy property, then you have to set OrderByOn to True, so the OrderBy gets activated.

    However, if the natural sort order at opening (laufende Nr. ;-))doesn't change, you could put an ORDER BY clause in the RecordSource query and leave the Load proc. I just tried this out - I have a subform with ascending order in the query, I sorted it per menu command descending, closed the whole thing, reopened - and I have on the screen the original ascending order now.

Posting Permissions

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