Ms Access 简明教程

MS Access - Controls & Properties

在本章中,我们将介绍 Access 中可用的 Controls and Properties 。我们还将学习如何向表单添加控件。控件是表单或报告的组成部分,您使用这些控件可以 enter, edit,display 数据。使用控件,您可以查看和处理数据库应用程序中的数据。

In this chapter, we will be covering Controls and Properties available in Access. We will also learn how to add controls to forms. Controls are the parts of a form or report that you use to enter, edit, or display data. Controls let you view and work with data in your database application.

  1. The most frequently used control is the text box, but other controls include command buttons, labels, check boxes, and subform/subreport controls.

  2. There are different kinds and types of controls you can create, but all of which will fall into one of the two categories — bound or unbound.

Bound Controls

我们现在来了解一下什么叫绑定控件。

Let us now understand what Bound Controls are −

  1. Bound controls are ones that are tied to a specific data source within your database such as a field and a table or a query.

  2. Values can be either text, dates, number, check boxes, pictures or even graphs.

  3. You use bound controls to display values that come from fields in your database.

Unbound Controls

我们现在来了解一下什么叫未绑定控件。

Let us now understand what Unbound Controls are −

  1. Unbound controls on the other hand are not tied to a data source, and they exist only in the form itself.

  2. These can be text, pictures or shapes such as lines or rectangles.

Control Types

您可以在 Access 中创建不同类型的控件。这里,我们将讨论一些常见的控件,如文本框、标签、按钮标签控件等。

You can create different types of controls in Access. Here, we will discuss a few common ones such as Text box, Label, Button Tab Controls etc.

Text Box

  1. Typically, anything that is in a text box will be bound, but not always.

  2. You can use these controls to interact with the data stored in your database, but you can also have unbound text boxes.

  3. Calculated controls will perform some kind of calculation based on an expression that you write and that data is not stored anywhere in your database.

  4. It is calculated on the fly and live just on that one form.

Labels

  1. Labels will always be text and unbound.

  2. Normally, labels are not connected to any source in your database.

  3. Labels are used to label other controls on your form such as text boxes.

Button

  1. This is another type of popular control; these command buttons usually perform a macro or module.

  2. Buttons are usually used to interact with the data or objects within your database.

Tab Controls

  1. Tab controls give you a tabbed view of controls or other controls in your form.

  2. Adding tabs to a form can make it more organized and easy to use, especially if the form contains many controls.

  3. By placing related controls on separate pages of the tab control, you can reduce clutter and ease your work with data.

  1. Hyperlink creates a hyperlink on your form to something else. It can either be a web page or even another object or place within your database.

Some Other Controls

现在让我们来看看其他一些控件−

Let us now look into some other controls −

  1. You can also create a web browser control and navigation control, groups, page breaks, combo boxes.

  2. You can create charts, lines, toggle buttons, list boxes, rectangles, check boxes, unbound object frames, attachments, option buttons, subforms and subreports, bound object frames and even place images on your form.

Example

现在让我们通过创建一个新的空白表单,看看其中一些控件的简单示例。转至 Create 组中的 forms 选项卡,然后单击 Blank Form

Let us now look at a simple example of some of these controls by creating a new blank form. Go to the Create tab in the forms group and click on Blank Form.

blank form

上述步骤将打开一个未绑定的表单,该表单尚未附加到我们数据库中的任何项目。

The above step will open an unbound form, which is not attached yet to any item in our database.

field list

默认情况下,它将以布局视图打开,如上图所示。

By default, it will open in layout view as shown in the above screenshot.

现在让我们转到“设计”视图以添加字段。

Let us now go to the Design View to add fields.

add design fields

在“设计”选项卡上,单击“属性表”。

On the Design tab, click on the Property Sheet.

property sheet design

在“属性表”中,单击下拉箭头并确保选择了“表单”,然后转到“数据”选项卡。

On the Property Sheet, click on the drop-down arrow and make sure Form is selected, and then go to the Data tab.

details property

在“数据”选项卡上,您将看到记录源仍然为空白。让我们假设我们想要创建一个将绑定到我们数据库中两个不同表的表单。现在单击…按钮。它会进一步打开其自己的查询生成器。

On the Data tab, you will see that the Record Source remains blank. Let us assume, we want to create a form that’s going to be tied to two different tables in our database. Now click on … button. It will further open its own query builder.

query builder

选择包含您要显示的数据的表;单击“添加”按钮,然后关闭此对话框。

Select the tables that contain the data you want to display; click on the Add button and then close this dialog box.

select property sheet

现在,让我们从 tblEmployees 中选择所有字段并将其拖动到查询网格中,并以类似的方式从 tblHRData 中添加所有字段。

Let us now select all the fields from tblEmployees and drag to query grid, and similarly add all the fields from tblHRData.

现在,单击“另存为”并为该查询命名。

Now, click Save As and give this query a name.

query2 save

我们称之为 qryEmployeesData 并单击 Ok ,然后关闭查询生成器。

Let us call it qryEmployeesData and click Ok and then close the query builder.

employee data

您现在可以看到该查询作为其记录源。我们现在已将此表单绑定到我们的数据库中的一个对象,在本例中是 qryEmployeesData。我们现在可以开始向此表单添加一些控件,要添加任何一个控件,请转到“设计”选项卡并从“控件”组中查看您的选项。

You can now see the query as its Record Source. We have now bound this form to an object in our database, in this case qryEmployeesData. We can now start by adding some controls to this form and to add any one of the controls, go to the Design tab and view your options from the controls group.

use control wizard

在控件菜单中,你将看到“使用控件向导”已高亮,如上图所示。默认情况下,这个小按钮周围有高亮框。这意味着控件向导已打开。这就像一个切换开关。当你点击切换开关,向导就会关闭。再次点击它,将再次打开向导。

From the Controls menu, you will see that the Use Control Wizard is highlighted as in the above screenshot. This little button has that highlighted box around it by default. This means that the control wizards are turned on. This is like a toggle switch. When you click on the toggle switch the wizards turn off. Clicking it again will turn the wizards on.

现在让我们点击标签,拖动此标签,输入“员工信息”,然后转到“格式”选项卡,按以下屏幕截图进行格式化。

Let us now click on the Label and drag this label and enter Employee Information and then go to the Format tab to format it as in the following screenshot.

detail employee information

你可以选择应用粗体样式或更改该标签内文本的字体大小等。此控件显示在表单的详细信息部分。最好将此标签放在表单页眉部分中,该部分暂时不可见。

You can choose to apply a bold style or change the font size of text inside that label etc. This control appears inside the detail section of your form. It makes more sense to position this label inside the form header section, which is not visible yet.

header section

右键单击表单背景的任意位置,并选择 Form Header ,如上图所示。

Right click anywhere in the background of that form and choose Form Header as in the above screenshot.

form header

将此控件移动到表单页眉区域。现在让我们从“设计”选项卡创建更多控件。此时,假设我们要将所有字段分发到两个不同的选项卡中。

Move this control into the Form Header area. Let us now create some other controls from the Design tab. At this point, Let us say, we want to distribute all our fields into two different tabs.

header area

在控件菜单中,你可以看到“选项卡控件”,将创建表单上的选项卡。单击选项卡控件,并在详细信息部分中将其绘制到表单上,如上图所示。

From the control menu, you can see the Tab Control which will create tabs on your form. Click on the tab control and draw it on your form in the detail section as in the above screenshot.

tab control

它将创建两个选项卡 - 页面 2 和页面 3,如上图所示。

It will create two tabs — page 2 and page 3 as in the above screenshot.

现在让我们开始向此选项卡控件添加一些控件。

Let us now start by adding some controls to this tab control.

如果我们想查看基本查询中存储的一些信息,请从“工具”组中的功能区单击 Add Existing Fields 选项,以查看基本查询中的所有可用字段。

If we want to view some information that’s stored in our underlying query, click on the Add Existing Fields option from the Ribbon in Tools group to view all the available fields from our underlying query.

existing fields

若要将现有字段添加到页面中,请如以下屏幕截图所示,选择“字段列表”中可用的所有字段。

To bring the existing fields to the page, select all the fields available in the Field List as in the following screenshot.

fields available

现在,将字段拖动到选项卡控件的 Page2,如以下屏幕截图所示。

Now, drag the fields to Page2 of the tab control as in the following screenshot.

drag fields

现在,转到“排列”选项卡并选择 Stacked 布局。

Now, go the Arrange tab and select the Stacked layout.

stacked layout

在第二页,现在让我们从此查询添加剩余字段。

On the second page, let us now add the remaining fields from this query.

remaining fields

你可以浏览并调整这些控件的大小和宽度,以使其按你希望的方式显示。

You can go through and make any adjustments to the size and width of these controls to get it looking the way you like.

完成格式化后,单击 Save As 图标,使用你希望的名称保存表单。

Once you are done with formatting click on the Save As icon to save the form with the name you want.

save employee data

单击“确定”,然后转到“表单”视图,以查看该表单中的所有信息。

Click Ok and go to the Form view to view all the information in that form.

view information

选项卡控件将我们的控件或字段分成两个屏幕,以便更轻松地查看和添加信息。

The tab control is breaking up our controls or our fields into two screens to make viewing and adding information easier.

adding information easier