• OrderBy property in a subform

    • This topic has 5 replies, 3 voices, and was last updated 24 years ago.
    Author
    Topic
    #356514

    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

    Viewing 0 reply threads
    Author
    Replies
    • #527826

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

      HTH thumbup

      • #527836

        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

        • #527846

          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 thumbup

          • #527855

            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()

            • #527878

              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.

    Viewing 0 reply threads
    Reply To: OrderBy property in a subform

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: