Solved

How can I add a sort button to my form?

Posted on 2009-07-07
5
386 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
[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
  • 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

Industry Leaders: 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!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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.

749 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