assending / dessending

inbal

Registered User.
Local time
Today, 04:18
Joined
Feb 8, 2009
Messages
48
i have a label with the following code:

Private Sub date_Label_Click()
Me.OrderBy = "date ASC"
Me.OrderByOn = True
End Sub

how can i change it so on the first click it will arrange by desending dates and on the second click arrange by assending dates?
 
Use an If statement to test for the current state and set it to the opposite.
 
yAssuming that your code to sort is correct, you can toggle the label's caption as well as the sorting of the column like this:
Code:
Private Sub Form_Load()
  ToggleLabelName.Caption = "Sort Date Ascending"
End Sub

Private Sub ToggleLabelName_Click()
  If ToggleLabelName.Caption = "Sort Date Ascending" Then
    ToggleLabelName.Caption = "Sort Date Descending"
    Me.OrderBy = "date ASC"
    Me.OrderByOn = True  
 Else
   ToggleLabelName.Caption = "Sort Date Ascending"
   Me.OrderBy = "date DESC"
   Me.OrderByOn = True
  End If
End Sub
 
This is off the main topic, but if you have a field named DATE you should rename it as DATE is an Access Reserved Word.
 
Bob makes a good point. I was focused on the question, but of all the Reserved words, Date can be one of the most problematic when used as an object name! I've seen it used where it was actually resetting the PC's system date!
 
Bob makes a good point. I was focused on the question, but of all the Reserved words, Date can be one of the most problematic when used as an object name! I've seen it used where it was actually resetting the PC's system date!

Date is bad, but NAME is probably the worst one. :)
 

Users who are viewing this thread

Back
Top Bottom