Sorting/Filtering Numbers and Dates |
|
Sorting and Filtering Numeric Fields |
Sorting Numeric Fields |
As seen in Lesson 16, numbers provide support for counting in a database and there are different types of numbers, integers and floating-point. One of the particularities of numbers in data entry is that the user types them as they become available. One of the resulting evidences is that, at one time, the numbers in a column may appear disorganized. In some cases this would be just fine. |
At some other times, you would want to have the values arranged in incremental or reverse incremental orders. The incrementing of a list is the arrangement that goes from the lowest to the highest, such as 0, 1, 2, 3, 4, and so on. The reverse is the arrangement from the highest to the lowest. Microsoft Access provides all the tools necessary to arrange the list in the order of your choice. To sort the values of a column of a table, a query, or a tabular form in incremental order, click the column header or any field under it. Then, in the Sort & Filter section of the Ribbon, click the Ascending button . Alternatively, you can right-click a column header or any cell under it, and click Sort Smallest to Largest. |
You can also right-click the control or its label and click Sort Smallest to Largest. To get the records in reverse incremental order, right-click the control or its label and click Sort Largest to Smallest. |
||
Filtering Records in Numeric Order |
If you have columns that display numeric values, you can filter records with criteria that are based on those numbers and the types of numbers they have. You have many options. You can create a list of only records that use one particular value. You can create a list that includes numbers of a certain range. You can create a list that includes numbers lower than a certain value or numbers higher than a certain value.
To filter records that are exactly equal to a certain value:
After clicking, the table or query would display only the records that share the value in the field.
Instead of getting the records that use the same value for a column, you may want the records that use values other than a particular one. To create such a list:
To use the Equals option, you must click the exact value you want to use as the basis for comparison. Some times, you will need to act on a range of values. To do this, you can right-click any value under a column for a table or query, or a control or its accompanying label on a form, then position the mouse on Number Filters and select from the menu that appears. Here is an example:
As seen for strings, a dialog box would appear. What you do in the Custom Filter dialog box depends on a few factors. If you had selected:
To get the records that have a value greater than or equal to a certain value, you have two options:
Practical Learning: Filtering Records |
Introduction |
||
Dates and times represent valuable items of a database. Although they mostly use numbers, their values represent spatial occurrences and therefore are treated accordingly. As done for strings and numbers, fields with date and time values can be sorted. For date values, the results of sorting produce a chronological or a reverse chronological order. Because a date (or time) is a spatial value, it can be considered as occurring:
Sorting the Records
As we saw in Lesson 18, there are various formats and rules for date and time values. Consider the following table:
When it comes to dates and times, you can sort values. When Microsoft Access is asked to sort dates or times, it refers to the Regional and Language Settings of Control Panel. This means that the rules may be different from one language to another.
To sort the records of a table, query, or form, first identify the column or control you will use. On the table or query, you can click a field under the column of your choice. On a form, you can click a control or its accompanying label. Then:
You can also right-click to sort date or time-based fields. Right-click the column header or a field under the column and click Sort Oldest to Newest
If the column or control contains empty values, they would appear first. After the empty records, the oldest record would show. The list would end with the record with the most recent value. As mentioned for the sorting of other types, each record is kept with its values for each column. Therefore, when the records are sorted, Microsoft Access first refers to the field you selected and displayed the other values of the corresponding records in their fields. If two records of a column have the same values, they are displayed in the same range and the records of the next column are sorted:
This scenario also applies to time-based columns.
As opposed to a chronological order, you can also sort records in reverse chronological order. To do this:
As mentioned already, after sorting a column, the corresponding values display on its left and right. If two records have the same value for a column, they are listed and Microsoft Access sorts the records of the next column in chronological order. If you want, you can sort the records of the next column in reverse chronological order. The first records sorted chronologically would keep their sequence and the records in the new column would be sorted:
This description applies to time-based column also.
Practical Learning: Sorting Date-Based Fields |
Filtering by a Specific Date or Time |
||
A date or a time can be considered either as a constant value or as a range of values. When examining the values of a list, you may want to include only some values and/or to exclude some others. This means that you can filter values based on a date, a time, or even a combination of both. To filter the records on a table, a query, or a form, once again you have various options. To get a list of records that occur at the same date or time, you can:
After clicking, the table or query would display only the records that share the (exact) same date or time in the field:
Filtering by (Only) a Specific Month, Day, or Year
Instead of a whole date or time, you can filter using only a specific day of all months, a specific month of all years, or a specific year in all records. These depend on how the values are entered and/or how the values display (or are accessed). For example, if a date-based column is configured to display its values in short date (Format = Short Date):
Instead of selecting the number for the day, if you are working on records that involve today's date, you can filter by today, yesterday or tomorrow. To do this, right-click a date in a field or an empty field that is supposed to hold a date value, position the mouse on Date Filters and select from the list:
If you select | Microsoft Access |
Today | Finds all records that occur on today's date |
Yesterday | Finds all records that occurred the day before today |
Tomorrow | Finds all records that will occur tomorrow |
It is helpful to remember that yesterday, today, and tomorrow each has an exact (referred to as constant) date. The user will know this date when performing the filtering operation
Practical Learning: Filtering By Year |
Filtering Records Related to the Current Date |
If you are working on a series of records that use the same values as your current week, your current month, your current quarter, or your current year, you can use one of these values as a base to filter. To do this, you can right-click a date in a field or an empty field for a date, position the mouse on Date Filters and select from the list:
Once again, remember that when you select an option, Microsoft Access refers to the system clock of the computer on which the operation is being performed:
If you select | Microsoft Access |
This Week | Finds all records entered for the current week, not the last few days and the next few days. Microsoft Access uses the rules of the language of the computer. For example, in US English, the week starts on Sunday and ends on the following Saturday. If you are on Friday and select This Week, Microsoft Access would consider records from Sunday of this week until tomorrow Saturday |
Last Week | Finds the records that were entered for last week, not the last 7 days. Microsoft Access uses This Week as the basis |
Next Week | Finds all records that have been entered for next week, not for the next 7 days |
This Month | Finds all records that have been entered for this month |
Last Month | Finds all records that exist for last month, not the last 30 days |
Next Month | Finds all records that exist for next month, not for the next 30 days |
This Quarter | Finds all records that have been entered for this quarter |
Last Quarter | Finds all records that have been entered for last quarter |
Next Quarter | Finds all records entered for the next quarter |
This Year | Finds all records entered for this year |
Last Year | Finds all records entered for last year |
Last Year | Finds all records entered for last year |
Year To Date | Finds all records that occur from the beginning of this year to now. Remember that to determine now, Microsoft Access refers to the system clock |
Filtering a Range of Dates or Times
If you do not know the exact date you want to filter by, you can/should consider working on a range of dates. You have many options. To start, you can right-click any field under the column of a table or query, or right-click a control or its accompanying label on a form, position the mouse on Date Filters and choose one of the options. If you click Equals..., Does Not Equal..., Before..., or After... option, the Custom Filter dialog box would come up. To assist you with filtering and to select an exact date, the Custom Filter dialog box is equipped with a picture button that, when clicked, would display a calendar:
When using the Custom Filter dialog box for a date-based column, you can type an exact date or use the calendar to select a date, which would reduce the likelihood of mistakes. If you are working on a time-based field, then you must type a valid time value in standard or military format.
Consider the following table of customers staying in a hotel:
If you right-click a cell under Reservation or right-click a control for the reservation date, position the mouse on Date Filters and click:
In the same way, you can use any of the logical operators to find the
records that occur on a certain date or time (simply enter the date or
time), before (<) a certain date or time, before or on (<=) a
certain date or time, after (>) a certain date or time, after or on
(>=) a certain date or time, or not (<>) on a certain date or
time
If you right-click a cell under a column or right-click a control or its accompanying label for a date, position the mouse on Date Filters and click Between... Alternatively, you can click a date-based field. Then, on the Ribbon, click Selection and click Between. In both cases, the Between Dates dialog box with two text boxes would display. In each text box, you can type a specific date or add a comparison operator to a date or time. This means that you can enter an exact date for each text box. Here is an example:
When you click OK, Microsoft Access would look for records that occur between both dates:
Notice that, on the Between Dates dialog box, the first label uses the caption Oldest and the other text box uses the Newest label. This is used only as a guide. You can enter a newer date in the first text box and an older date in the second text box:
You would get the same result. Although there is hardly any justification for that, you can use comparison operators in the text boxes, in none of the text boxes, or in one and not the other text boxes. Microsoft Access would apply the operators and use Boolean algebra to get the results.
Using the Between Dates dialog box is equivalent to using the logical AND operator that we will study in Lesson 25.
Practical Learning: Filtering a Range of Dates or Times |
Introduction |
||
As seen in Lesson 13, a Boolean field is one that holds a true or false result and it is created as a Yes/No type. By default, and most of the time, a Boolean field displays a check box that can be checked (or marked) or cleared (or unchecked). By its Boolean interpretation, Microsoft Access considers that a check box that is checked is "selected" and a check box that is not checked in "cleared". You can use this logic to sort the records of a table, a query, or a form.
You can sort the Boolean records as selected or cleared. As it should seem obvious, when you sort in selected order, the checked boxes would come up first. To sort the Yes/No records of a table, a query, or a form, in selected order, you can:
Once the check box has received focus, in the Sort & Filter section of the Ribbon, click the Ascending button
To sort the Boolean records in cleared order:
To put the list back in the sequence it previously had, in the Sort & Filter section of the Ribbon, click the Clear All Sorts button .
Practical Learning: Introducing Sorting Records
Filtering Boolean Records
If you have a column created as a Yes/No type, you can isolate the list with only checked or only cleared fields. To filter records that are checked:
After clicking, the table, query, or form would display only the records that have that field checked.
To filter records by the cleared check boxes:
After clicking, the table, query, or form would display only the records that have that field cleared.
Practical Learning: Filtering Records
MCAS: Using Microsoft Office Access 2007 Topics |
P1 | Sort data |
Exercises
Yugo National Bank
Watts A Loan
World Statistics
US Senate
|
||
Previous | Copyright © 2008-2016, FunctionX, Inc. | Next |
|