Toggle between ASC/DESC order

G

Guest

I am interested in the answer to Jerry's question on November 11, 2004:
"Is it possible to code a command button (on click event) such that it will
replicate what happens when you click the sort icon in the toolbar (that >
A-->Z icon)?"

Here was RBrandt's reply:

"Me.OrderBy = Screen.PreviousControl.ControlSource
Me.OrderByOn = True "

I attached the code to the on_click event of the control in my form, and it
sorts in ASC. However, what code do I use to toggle the sort order between
ASC/DESC for the column on my form?

Thank you in advance.
 
D

Dirk Goldgar

Carole said:
I am interested in the answer to Jerry's question on November 11,
2004: "Is it possible to code a command button (on click event) such
that it will replicate what happens when you click the sort icon in
the toolbar (that > A-->Z icon)?"

Here was RBrandt's reply:

"Me.OrderBy = Screen.PreviousControl.ControlSource
Me.OrderByOn = True "

I attached the code to the on_click event of the control in my form,
and it sorts in ASC. However, what code do I use to toggle the sort
order between ASC/DESC for the column on my form?

Thank you in advance.

Something like this (untested):

'----- start of code -----
If Me.OrderByOn Then
If Screen.PreviousControl.ControlSource = Me.OrderBy Then
Me.OrderBy = Me.OrderBy & " DESC"
Else
Me.OrderBy = Screen.PreviousControl.ControlSource
End If
Else
Me.OrderBy = Screen.PreviousControl.ControlSource
Me.OrderByOn = True
End If
'----- end of code -----
 
A

Alex

Hi Carole,

Ether use a global variable to hold the current value of the ASC/DESC
or a hidden checkbox on the form that is set with the click event of
the button

e.g.

the most reliable way I have found is

If Me.Check0.Value = 0 Then
Me.Check0.Value = 1
Else
Me.Check0.Value = 0
End If

I personally don't use any of the form filtering function instead I do
a dynamic build of the SQL recordsource for the form, with the ASC or
DESC on the end of the select statement, with a refresh after.

Hope it helps

Regards

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top