Solved

Sort buttons in access 2003 FORM

Posted on 2009-05-08
8
484 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
  • 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
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now