?
Solved

Sort buttons in access 2003 FORM

Posted on 2009-05-08
8
Medium Priority
?
491 Views
Last Modified: 2013-11-28
How do I create a command button in an access FORM to sort ascending and descending?

I tried using the runcommand with ascending/descending, but access 2003 says it cannot run that command at this time.
0
Comment
Question by:jbradford777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24337209
What do you want it sorted by? by any field on the screen or selected fields?

if u right click on a field, there is already a sort option
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24337234
to order in vba, you do this

Me.OrderBy = "MyFieldName"
Me.OrderByOn = True

'descending is
Me.OrderBy = "MyFieldName DESC"


0
 

Author Comment

by:jbradford777
ID: 24337334
OK, I realize there are sort buttons already on a form, however I need to add buttons for people who don't use access...no right clicking, no nothing, just a button that tells them they can sort.  It's to sort by any field in the form.  I just started writing VBA, so, I really don't know how to start or finish the code you placed above???
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 24337389
ok, a form can have several fields right? lets say you want to filter on one or more. But to avoid confusion as what the sort is, maybe a button next to each textbox that you want to sort on.

So create a button, lets say its called txtFred. The fieldname in this table is called Wilma. So on the click event of txtFred, you would want to sort by Wilma.
If you want it toggable so it orders by ascending or descending then we simply check the current order value

eg

private sub txtFred_Click()

    if Me.OrderBy = "Wilma" then
        Me.OrderBy = "Wilma DESC"
    else
        Me.OrderBy = "Wilma"
    end if
    Me.orderbyon =true
end sub
0
 

Author Comment

by:jbradford777
ID: 24338030
OK, what if it's highest cost vs. lowest cost (not a text field, it's a number)

The field name is 4-Week Total Cost...do I put it in [4-Week Total Cost] brackets or "4-Week Total Cost"?
0
 

Author Comment

by:jbradford777
ID: 24338250
oh, here's the code...it works, but it only sorts one way, how do you put the toggle in to switch from asc to desc.?

Private Sub Command72_Click()
   
    If Me.OrderBy = [4-Week Total Cost] Then
        Me.OrderBy = [4-Week Total Cost DESC]
    Else
        Me.OrderBy = "4-Week Total Cost"
    End If
    Me.OrderByOn = True

End Sub
0
 

Author Closing Comment

by:jbradford777
ID: 31579459
THANK YOU!!!!!!!!!!!!!!!!!!!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24340076
Needs to be in quotes and text consistent


If Me.OrderBy = "[4-Week Total Cost]" Then
        Me.OrderBy = "[4-Week Total Cost DESC]"
    Else
        Me.OrderBy = "[4-Week Total Cost]"
    End If
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question