Solved

How can I add a sort button to my form?

Posted on 2009-07-07
5
352 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 19

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 19

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

707 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

14 Experts available now in Live!

Get 1:1 Help Now