Ms Access 简明教程

MS Access - Formatting

Access 中的一个特别有用的格式化工具是能够应用 Conditional Formatting 以突出显示特定数据。让我们做一个条件格式的简单示例。

One especially useful formatting tool in Access is the ability to apply Conditional Formatting to highlight specific data. Let us take a simple example of conditional formatting.

Example

在这个示例中,我们将在数据库中使用表单 fSubCurrentProjects

In this example, we will be using a form fSubCurrentProjects in our database.

current project

我们有这个数据库中所有项目的清单,我们还有一些新字段,如 On Time StatusNumber of Late Tasks 。此表单是通过另一个查询创建的。

We have a list of all of the projects in this database and we have also got a couple of new fields like the On Time Status and the Number of Late Tasks. This form is created from another query.

completed

在此查询中,我们有一个表与查询之间的联接,查询将显示到期日期计数或有多少项目有逾期任务。我们这里还有一个计算字段,它使用 IF 函数来确定到期日期的计数是否大于零。如果项目已逾期,它将显示单词 Late ;如果特定项目没有逾期任务,它将显示 On Time

In this query, we have a join between a table and a query that will display the count of due dates or how many projects have tasks that are overdue. We also have a calculated field here that uses the IF function to determine whether or not the count of the due date is greater than zero. It will then display the words Late if the project is late or On Time if that specific project does not have any overdue tasks.

on time

Example 1

在此示例中,我们将使用上面的表单来了解如何使用条件格式突出显示特定信息。我们现在将突出显示当前逾期的每个项目。若要将条件格式应用于一个字段或多个字段,我们需要切换到“布局”视图。

In this example, we will be using the above form to understand how you can use Conditional Formatting to highlight specific pieces of information. We will now highlight every single project that is currently running late. To apply Conditional Formatting to one field or more than one field, we will need to switch over to the Layout view.

现在,选择 On Time Status 字段。

Now, select the On Time Status field.

time status

现在,转到“格式”选项卡。

Now, go to the Format tab.

format tab

在此“格式”选项卡上,您应看到一个名为“控件格式”的组和一个用于“条件格式”的特殊按钮。现在,我们单击“条件格式”。

On that Format tab, you should see a group called Control Formatting and a special button for Conditional Formatting. Let us now click on Conditional Formatting.

rules manager

现在,您将看到一个条件格式规则管理器,目前我们未对此控件应用任何规则。现在,通过单击“新建规则”按钮来创建新规则。

You will now see a Conditional Formatting Rules Manager and currently we have no rules applied to this control. Let us now create a new rule by clicking on the New Rule button.

new rule

现在,您将看到一个“新建格式规则”对话框。我们首先将指定将要创建的规则类型,这里有两个选项。第一个选项是 check the values in the current record or to use an expression ,第二个选项是 compare this record with the other records

You will now see a New Formatting Rule dialog box. We will first specify the type of rule we will be creating and here we have two options. The first option is to check the values in the current record or to use an expression, and the second option is to compare this record with the other records.

我们现在表单中只有两个值之一;“准时”或单词“逾期”,并且这些来自给定查询。现在,让我们从第一个组合框中选择“ Field Value Is ”,然后从第二个组合框中选择“ equal to ”。现在,在引号中输入单词“ Late ”。

We now have only one of two values in our form; either On Time or the word Late and that is from the given query. Let us now select the “Field Value Is” from the first combo box and then select “equal to” from the second combo box. Now, type the word “Late” in quotation marks.

equal to

我们现在可以设置我们的条件格式,如果单词 Late 出现在该字段中,我们希望此字段的外观如何。现在,让我们将字体颜色更改为红色,并使其 bold, italicunderline ,这就是我们的条件规则。现在,让我们单击 Ok ,再单击 ApplyOk

We can now set our Conditional Formatting, how we want this field to look like if the word Late appears in that field. Let us now change the font color to red and make it bold, italic and underline, and that’s our conditional rule. Let us now click Ok and then click Apply, and Ok again.

formatted late

您可以看到单词 Late 已格式化。这是一个创建非常基本的条件格式规则的示例。

You can see that the word Late is formatted now. This is one example of how to create a very basic conditional format rule.

Example 2

让我们以另一个示例说明。此处,我们将使项目的标题或名称 redbold, italicunderline 。在您的表单上选择项目名称控件。

Let us take another example. Here, we will make the title or the name of the project red and bold, italic and underline. Select the project name control on your form.

conditional formatting

我们现在将返回我们的“格式”选项卡并单击“条件格式”,并为特定控件创建新规则,如上方屏幕截图所示。

We will now go back to our Format tab and click on Conditional Formatting and create a new rule for that specific control as shown in the above screenshot.

no format set

此处,我们将不会检查已选择的当前字段的值,而是将其与此表单上的另一个字段进行比较。在第一个组合框中选择 Expression Is ,然后单击如上方屏幕截图中所示的末尾的 … 按钮。

Here, we will not be checking the value of the current field we have selected, but we will be checking it against another field on this form. Select Expression Is in the first combo box and then click on … button at the end as in the above screenshot.

expression builder

在“表达式类别”中,您具有此表单中的每个对象。双击 CountofDueDate 。这会将对控件或字段的引用发送到我们的表达式生成器,条件为大于零。现在,单击“确定”。

In the Expression Categories, you have every single object that is on this form. Doubleclick on CountofDueDate. This will send the reference to that control or that field up to our expression builder and condition if it is greater than zero. Now, click Ok.

formatting rule

现在,让我们单击“确定”,再单击“应用”并再次单击“确定”。

Let us now click Ok and then, click Apply and Ok again.

example value

这是基于另一个字段中的值的字段上条件格式的示例。

That was an example of Conditional Formatting on a field based on values in another field.

Example 3

我们现在来看看条件格式的另一个示例。假设我们希望查看哪些项目比其他逾期项目更加逾期或有更多逾期任务。选择“条件格式”选项。

Let us now look at another example of conditional formatting. Let us assume, we want to see which projects are more late or have more late tasks than other late projects. Select the Conditional Formatting option.

count due date

单击新建规则按钮以创建新规则,然后单击确定,如上图所示。

Click on the New Rule button to create a new rule and then click Ok as in the above screenshot.

new formatting rule

在新建格式规则中,我们现在将选择规则类型“ Compare to other records ”。我们进一步更改 Bar color to red 。我们希望最短条形图表示最小值,最长条形图表示最大值。现在单击确定,然后再次单击应用和确定。

In the New Formatting Rule, we will now select a rule type “Compare to other records”. Let us further change the Bar color to red. We want our shortest bar to represent the lowest value and the longest bar to represent the highest value. Let us now click Ok and then, click Apply and Ok again.

bar color red

你现在可以看到条件性阴影已应用,如上图所示。现在让我们转到表单视图。

You can now see Conditional Shading applied as in the above screenshot. Let us now go to the Form view.

conditional shading