Changing the OrderBy of a SubForm prorgamatically

ojeffery

Registered User.
Local time
Today, 17:05
Joined
Nov 13, 2009
Messages
11
I have a Form with a (Continuous) Subform that lists the results of a query. There's a header within the Subform that has several elements you can click on to programatticaly change the OrderBy of the Subform then refresh it. An example of the code I use is here:

Code:
Private Sub CompanySort_Click()
If (Me.OrderBy = "Company") Then
Me.OrderBy = "Company DESC"
Else
Me.OrderBy = "Company"
End If
Me.Refresh
End Sub

This works fine when the Form (which is named "Results Subform") is run by itself, but doesn't work when run as part of the parent Form ("Results"). The name of the Subform control is "Report subform", can't remember why it's different now...

What am I doing wrong? I'm sure it's simple, but I'm stumped, any help is much appreciated.
 
I have a Form with a (Continuous) Subform that lists the results of a query. There's a header within the Subform that has several elements you can click on to programatticaly change the OrderBy of the Subform then refresh it.

Bravo!!! :D I happen to design UI's in the same way.

I found that forms remember their Filter and Order preferences, so I have coded a generic sub to reset the form each time it is opened:

Code:
        With frm
          .Filter = vbNullString
          .FilterOn = False
          .OrderBy = vbNullString
          .OrderByOn = False
        End With
Then when actually switching the ORDER BY in the QueryDef that populates the form, this is the Rx I use to accomplish that:

Code:
  'Update the query the form is using
  MePointer.RecordSource = strQueryDef
  MePointer.Refresh
 

Users who are viewing this thread

Back
Top Bottom