Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2004
    Location
    OHIO
    Posts
    75

    Arrow Unanswered: sorting records alphabetically

    Simple deal, yet I cannot figure it out. I need to make a button that will sort records in a form from a to z or z to a.

    Anybody have a quick fix for me?

    I appreciate it!

    B

  2. #2
    Join Date
    Jul 2004
    Posts
    125
    Yes, it is very simple, however your information is too vague but, in general, you can set the OrderBy property of the form in code, to sort by the desired field, Ascending or Descending.

  3. #3
    Join Date
    Jan 2004
    Location
    OHIO
    Posts
    75

    Red face response to being to general

    ok, maybe some detail will help

    I have a database of volunteers and I want to sort them with one button. Initially when the form is loaded the volunteers are sorted Ascending, I believe....so I need a toggle button that shows the image for Desending and when it is click the image changes to a Ascending image, i.e. A->Z and sorts them.

    This make sense? I need to sort the volunteers by there LastName.

  4. #4
    Join Date
    Jul 2004
    Posts
    125
    Create 3 command buttons and on the OnClick property, copy the following code and change the Control names between the quotes.

    Private Sub Ascending_Click()
    With Me
    .OrderByOn = True
    .OrderBy = "LastName"
    End With
    End Sub

    Private Sub Descending_Click()
    With Me
    .OrderByOn = True
    .OrderBy = "LastName DESC"
    End With
    End Sub

    Private Sub Natural_Click()
    With Me
    .OrderByOn = False
    .OrderBy = ""
    End With
    End Sub

  5. #5
    Join Date
    Jan 2004
    Location
    OHIO
    Posts
    75

    Cool that will work, but...

    I was hoping to do that with a toggle command button so i do not have to have so many buttons... any ideas?

    when it loads the volunteers are sorted A -> Z so really i need a toggle to sort Z -> A and when they press it, it sorts and the icon (button image) changes to A -> Z....

    make sense?

    Although, I do appreciate the code that you dropped!

    Thanks,

    B

  6. #6
    Join Date
    Jan 2004
    Location
    OHIO
    Posts
    75

    this is some code that i'm working with now....but

    This code below does sort of what I am looking to do. But it does not change the image icon and i have to hold the shift key to get it to sort Ascending to Desending... I would like to eliminate the need for holding the shift key down and I want the images to change....thought this code might help spark something...


    Code:
    Private Sub Sort_LastName_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Application.Echo False 'Turn Echo off to Prevent flicker
        If Shift = 1 Then 'Is the Shift Key pressed (1 = yes : 0 = No)
         'Descending Order
         Me.OrderBy = "[LastName] DESC" 'The table item to base the sort from.
        Else
         'Ascending Order
         Me.OrderBy = "[LastName]" 'The table item to base the sort from.
        End If
        Me.OrderByOn = True 'Turn ON the Sort
        Me.Requery 'Requery the Form
        Application.Echo True 'Turn Echo back on
    End Sub
    Last edited by ironchef; 08-18-04 at 16:49.

  7. #7
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511

    Smile

    You can sort from A-Z and Z-A with one button.

    Assign a descriptive caption to your button, such as "Sort Z-A". In the click event of your button, test for this caption and do the appropriate sort. For example:

    If Me!cmdSorter.Caption = "Sort Z-A" Then
    ...code to sort descending
    Me!cmdSorter.Caption = "Sort A-Z"
    Else
    ...code to sort ascending
    Me!cmdSorter.Caption = "Sort Z-A"
    End If

    Jerry

  8. #8
    Join Date
    Jul 2004
    Posts
    125
    You can also do it with on Toggle button (Up value = False, Down Value = True) and paste the code I've posted with minor modifications. Also, you may be able add the standard graphic .bmp's that comes with Access, for sort AZ or ZA.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •