Results 1 to 8 of 8
  1. #1
    coolwhisper is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    10

    Exclamation How to use one Button for Sorting in Ascending & Descending




    Dear All

    I would like to do sorting by using one Button like (Toggle Button)

    In the first click the below code is work good for Descending
    but in the second click the code doesn't work for Ascending!!



    Code:
     
    Private Sub TabItemName_Label_Click()
    If [TabItemName_Label] = -1 Then
        Me.OrderBy = TabItemName & " DESC"
        Me.OrderByOn = True
    Else
        Me.OrderBy = TabItemName
        Me.OrderByOn = True
    End If
    End Sub
    Could you please try to help and give suitable solution ?

    Many thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    It looks like you are clicking a label, can you tell us more about the "Button" you want to click?

    What do you think you code is doing?
    What is the record source of your form?

  3. #3
    coolwhisper is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    10
    Dear
    please see tha attached photo

    The question : How I can us a Toggle Button with a code ?
    Thanks




    Click image for larger version. 

Name:	0001.png 
Views:	11 
Size:	95.5 KB 
ID:	11346

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    What is the record source of your form?

  5. #5
    coolwhisper is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    10
    thank you
    but I do not know how to change the type of this !

    I need only any code can work with Toggle Button
    Last edited by coolwhisper; 03-01-2013 at 03:19 AM.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    If you are going to use a button to change sort order, you should identify WHAT data is to be sorted.

    Is this a school assignment or something that want you to use a toggle button?

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    In your first post you asked for some code.
    Here is some code showing how a toggle button could be used.

    Notice how the data sort order (see AName column) changes.

    I am attaching some jpgs to show the effect of clicking the toggle with the sample code.
    Below is the code for the Form Load event, and the Toggle click event

    Form Load code
    Code:
    Private Sub Form_Load()
    Dim sCaption As String
    Me.RecordSource = "SELECT A.AnimalId, A.SightingDate, A.GPSLat, A.GPSLong, Animal.AName, AnimalCapture.CaptureDate" _
      & " FROM (AnimalLocs AS A INNER JOIN Animal ON A.AnimalId = Animal.AnimalId) INNER JOIN AnimalCapture ON Animal.AnimalId = AnimalCapture.AnimalId " _
      & " ORDER By Aname ASC;"
    sCaption = "Toggle To Sort on AName"
    Me.Label16.Caption = sCaption
    End Sub
    Toggle Click code
    Code:
    Private Sub Toggle13_Click()
     If Me.Toggle13 = True Then
     Me.Label16.ForeColor = vbBlack
     Me.Label16.Caption = "DESCENDING"
     Me.RecordSource = Replace(Me.RecordSource, " ASC", "  DESC")
     Else
     Me.Label16.ForeColor = vbBlue
     Me.Label16.Caption = "ASCENDING"
     Me.RecordSource = Replace(Me.RecordSource, " Desc", " ASC")
     End If
     Me.Requery
     
    End Sub
    Attached Thumbnails Attached Thumbnails FormWithToggleOnOpen.jpg   FormWithToggleOnFirstClick.jpg   FormWithToggleSecondClick.jpg  

  8. #8
    coolwhisper is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Posts
    10
    Thank you orange
    Now I got it ^_^

    Many thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to order columns in ascending order?
    By darkingthereturn in forum Access
    Replies: 5
    Last Post: 06-18-2012, 05:24 AM
  2. Replies: 11
    Last Post: 01-12-2012, 07:55 PM
  3. Make TEXTBOXES sort by DESCENDING order
    By taimysho0 in forum Programming
    Replies: 1
    Last Post: 12-05-2011, 04:52 PM
  4. Need Sorting Help
    By rbpd5015 in forum Access
    Replies: 1
    Last Post: 09-28-2009, 07:39 PM
  5. Replies: 0
    Last Post: 03-26-2007, 02:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums