Solved

Sorting Dates by Clicking Header/Label on a continuous form

Posted on 2006-11-21
4
322 Views
Last Modified: 2008-03-04
In my Access 2000 app I have a continuous form with three columns 'TicketNo', 'TicketDate' and 'Status'.  The labels for each of these columns in the form header are 'TicketNo_Label', 'TicketDate_Label' and 'Status_Label'.  I have logic in the 'click' event of each of the respective headers.  The logic is intended to sort the data in the column that has been clicked.  If the data is already in ascending sequence it should be sorted to descending sequence.  The logic is the same for all three field labels and it works perfectly for 'TicketNo' and 'Status' which are Strings.  The logic does nothing to sort the 'TicketDate' field which is a date.

How do I need to modify the following code to sort the date field?

Private Sub TicketDate_Label_Click()
If Me.OrderBy = "TicketDate DESC" Then
    Me.OrderBy = "TicketDate"
Else
    Me.OrderBy = "TicketDate DESC"
End If
Me.OrderByOn = True
End Sub

For reference, the following logic which is exactly the same except for the field name, works perfectly on the other two fields:

Private Sub Status_Label_Click() '
If Me.OrderBy = "Status DESC" Then
    Me.OrderBy = "Status"
Else
    Me.OrderBy = "Status DESC"
End If
Me.OrderByOn = True
End Sub

Private Sub TicketNo_Label_Click()
If Me.OrderBy = "TicketNo DESC" Then
    Me.OrderBy = "TicketNo"
Else
    Me.OrderBy = "TicketNo DESC"
End If
Me.OrderByOn = True
End Sub
0
Comment
Question by:mlcktmguy
  • 3
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 17993163
Your code should work... I added it to a sample db, and it worked fine.  Verify that the column you are sorting on is indeed a date field.  Also double check that the clik event code is actually "tied" to the command button... By clicking the "..." next to the On Click event in the form's properties sheet and Selecting "Code Builder" if given that option.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17993167
>in the form's properties sheet
Should have been "In the command button's property sheet"
0
 
LVL 1

Author Comment

by:mlcktmguy
ID: 17993264
Thanks you, you are absolutely correct.  It is now working.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17993271
Glad to help ;-)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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…
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 start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

772 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