Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sort buttons in access 2003 FORM

Posted on 2009-05-08
8
Medium Priority
?
493 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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