Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    Creating Sort Buttons in a Header in a list view

    Ok, so I hope I can be clear here.



    I'm new to Access, but I think I've resigned myself to what I want to do must be done using macros.

    I have a database with a ton of records. It also has a "List" form where I can scroll through a shortened version all my records. When I find the one I want, I click on it and it brings me to a different form with more detail about that record.

    What I want to do is create several buttons in the header of the List so that when I click on any one of them it will sort the records based on the value of one field. (Similar to how you can sort your e-mail by date received, sender, size, etc. by clicking on the list header.) For example I may want to sort by "ID" and if I don't find the record I'm looking for that way I want to be able to then have another button that will sort by "Name" (or size, weight, etc.)

    I've looked pretty hard for something that will accomplish this, but with no luck. Any help would be greatly appreciated.

    Cheers,

    marty

  2. #2
    ajetrumpet is offline Banned
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    take a look at the ORDERBY and ORDERBYON properties for the form. you're going to want to change these on the click of the buttons and then use REQUERY for the form to display the sorting.

  3. #3
    Join Date
    Mar 2010
    Posts
    3
    Ok, I think I get what you mean. I checked this answer you had given earlier and thought that the same thing might apply:

    i believe you do this using the ORDERBY property. so on the click on each label that holds the field names, put something like this on the click event property: Code:
    =sortfield("fieldname", "formname")

    then write a universal function like this: Code:
    public function sortfield(fld as string, frm as string)

    forms(frm).orderby = fieldname
    forms
    (frm).orderbyon = true
    forms
    (frm).requery

    end
    function


    \\

    Unfortunately, when I tried to do this, it didn't work. I would click the button and nothing would happen. I think I might be getting confused somewhere; should I be replacing "formname" with the form (List) I'm working in, the table where the records come from or the query that stores all the fields?

    Or am I way off altogether?

    Thanks again,

    marty

  4. #4
    ajetrumpet is offline Banned
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    this is fairly easy to do. I put together a small example for you in a cont. form. double click the labels to sort by the corresponding field.

    You can expand on this obviously, as this is the simple way to do it.

    Have a good night.

  5. #5
    Join Date
    Mar 2010
    Posts
    3
    Wow, Thanks a million dude; you totally went beyond and above the call of duty here.

    This was exactly what I was looking for. You are a prince.

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

Similar Threads

  1. How To View List of Files in Box
    By treyprice in forum Forms
    Replies: 3
    Last Post: 01-14-2010, 03:40 PM
  2. How to sort by three sort orders
    By captgnvr in forum Access
    Replies: 4
    Last Post: 11-09-2009, 07:30 AM
  3. Replies: 14
    Last Post: 06-24-2009, 07:36 PM
  4. Access 2003 - Creating Buttons from a Table
    By Speedy in forum Programming
    Replies: 2
    Last Post: 02-28-2009, 05:32 PM
  5. Creating a list viewed by 2 criteria
    By phillyon in forum Queries
    Replies: 0
    Last Post: 12-01-2008, 11:46 AM

Tags for this Thread

Posting Permissions

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