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
Solved

How can I add a sort button to my form?

Posted on 2009-07-07
5
378 Views
Last Modified: 2013-04-29
I am new to using Access 2007 runtime. Since runtime users don't have access to the ribbon they can't click on a field on a form and click on the sort button to sort records Acending or decending as they would if they clicked the sort button on the ribbon.

How do I program a sort button on the form so my user can select one of several fields to sort records?

Thanks in advance for your help.
0
Comment
Question by:Rwardlow
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:darbid73
ID: 24795188
would this do the trick

Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
'Purpose: Set a form's OrderBy to the string. Reverse if already set.
'Return: True if success.
'Usage: Command button above a column in a continuous form:
' Call SortForm(Me, "MyField")
 
 
If Len(sOrderBy) > 0 Then
' Reverse the order if already sorted this way.
If frm.OrderByOn And (frm.OrderBy = sOrderBy) Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
' Succeeded.
SortForm = True
End If
End Function

Open in new window

0
 
LVL 10

Accepted Solution

by:
therealmongoose earned 500 total points
ID: 24795207
I use the colume / field labels and put a sort process in on the on click event, but you could equally use buttons...
The syntax to sort by a field is as below:
 
The example below will sort ascending then decscending, depending on the current order...

Private Sub Label20_Click()
        
    If Me.OrderBy <> "[Your Field Name]" Then
        Me.OrderBy = "[Your Field Name]"
    Else
        Me.OrderBy = "[Your Field Name] desc"
    End If
 
    
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:Rwardlow
ID: 31600635
Thanks a lot, this is perfect.
0
 
LVL 1

Author Comment

by:Rwardlow
ID: 24795644
Thank you both for your solutions. I think both will work but the one I selected seemed to work better for me.
0
 
LVL 20

Expert Comment

by:darbid73
ID: 24795762
That is an interesting decision.  May I suggest you have a little bit of a look at how functions work and their flexibility.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

856 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