Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2005

Tip: Looking for answers? Try searching our database.

Toggle between ASC/DESC order

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carole - 15 Apr 2005 22:13 GMT
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.
Dirk Goldgar - 15 Apr 2005 22:23 GMT
> 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
[quoted text clipped - 11 lines]
>
> 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 -----

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Alex - 15 Apr 2005 22:37 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.