Sorting Report in Asc & Desc order

newbie87

Registered User.
Local time
Today, 09:04
Joined
Sep 9, 2011
Messages
43
Hi All,

I have a report that shows the data from my Information table.

One of the columns is called First_Name and under that header i have a button which sorts them into ascending order using the code below.

Code:
Private Sub btnFirstName_Click()

Me.OrderBy = "[FirstName] Asc"
Me.OrderByOn = True

End Sub
What I want to happen is, when the user clicks it once it sorts it into ascending order, and when they click it a second time it sorts into descending order
I understand I need to use an If/Else statement but I'm not sure how to write it, is it along the lines of..
Code:
Private Sub btnFirstName_Click()

If btnFirstName = True Then
btnFirstName.OrderBy = "[FirstName] Asc"
Me.OrderByOn = True
Exit Sub
Else
btnFirstName.OrderBy = "[FirstName] Desc"
Me.OrderByOn = True
End If
End Sub
any help would be appreciated.
 
Do you have a label you can set the caption to reflect the order by setting ?

Here is some air code.
Code:
If Me.LabelSortOrder.Caption = "Click To Sort Ascending" Then
btnFirstName.OrderBy = "[FirstName] Asc"
Me.OrderByOn = True
Me.LabelSortorder.Caption = "Click To Sort Descending"
ElseIf Me.LabelSortOrder.Caption = "Click To Sort Descending" Then
btnFirstName.OrderBy = "[FirstName] Desc"
Me.OrderByOn = True
Me.LabelSortOrder.Caption = "Click To Sort Ascending"
End If
End Sub

When you click the command button, the sort sort order changes and the label caption changes so when the button is clicked next time the sort order will be different.

You can change the label on the command button but you would have to set focus some hwere else in your code, I think.
 
Hi,

Thanks for your response, this is my code now but nothing happens when the button is clicked, no run time error messages appear, and the asc and desc does not work

Code:
Private Sub btnDate_Click()

If Me.lblText.Caption = "Click To Sort Ascending" Then
Me.OrderBy = "[FirstName] Asc"
Me.OrderByOn = True
Me.lblText.Caption = "Click To Sort Descending"
ElseIf Me.lblText.Caption = "Click To Sort Descending" Then
Me.OrderBy = "[FirstName] Desc"
Me.OrderByOn = True
Me.lblText.Caption = "Click To Sort Ascending"
End If
End Sub

Am i going wrong somewhere? :(
 
Hey,

Got it working

Code:
Private Sub btnDate_Click()

If Me.lblOrder.Caption = "Click To Sort Ascending" Then
Me.OrderBy = "[Current_Date] Asc"
Me.OrderByOn = True
Me.lblOrder.Caption = "Click To Sort Descending"
ElseIf Me.lblOrder.Caption = "Click To Sort Descending" Then
Me.OrderBy = "[Current_Date] Desc"
Me.OrderByOn = True
Me.lblOrder.Caption = "Click To Sort Ascending"
End If
End Sub

Thanks PNGBill
 

Users who are viewing this thread

Back
Top Bottom