Solved

Sort buttons in access 2003 FORM

Posted on 2009-05-08
8
487 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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