Ms Access 简明教程

MS Access - Create Form

Access 中的表单就像商店中的展示柜,可以更容易地查看或获取你想要的产品。由于表单是你可以或其他用户可用于添加、编辑或显示存储在你 Access 桌面数据库中的数据的对象,因此你的表单设计是重要因素。你可以使用 Microsoft Access 中的表单进行许多方面的设计。你可以创建两种基本类型的表单 -

Forms in Access are like display cases in stores that make it easier to view or get the items that you want. Since forms are objects through which you or other users can add, edit, or display the data stored in your Access desktop database, the design of your form is an important aspect. There’s a lot you can do design-wise with forms in Microsoft Access. You can create two basic types of forms −

  1. Bound forms

  2. Unbound forms

Bound Forms

我们现在了解一下什么是 Bound Forms -

Let us now understand what Bound Forms are −

  1. Bound forms are connected to some underlying data source such as a table, query, or SQL statement.

  2. Bound forms are what people typically think of when they think of the purpose of a form.

  3. Forms are to be filled out or used to enter or edit data in a database.

  4. Examples of bound forms will typically be what users use to enter, view or edit data in a database.

Unbound Forms

让我们查看未绑定表单 -

Let us look into Unbound Forms −

  1. These forms are not connected to an underlying record or data source.

  2. Unbound forms could be dialog boxes, switch boards, or navigation forms.

  3. In other words, unbound forms are typically used to navigate or interact with the database at large, as opposed to the data itself.

Types of Bound Forms

在 Access 中,您可以创建多种类型的绑定表单。我们来了解一下类型 −

There are many types of bound forms you can create in Access. Let us understand the types −

Single Item Form

这是最流行的一种,其中会显示记录——一次显示一条记录。

This is the most popular one and this is where the records are displayed — one record at a time.

Multiple Item Form

这会显示来自该绑定数据源的多个记录。

This displays multiple records at a time from that bound data source.

Split Form

表单被分成两半,垂直或水平。一半会显示一个单项或记录,另一半会显示一个列表或提供基础数据源的多个记录的数据表视图。

The form is divided into halves, either vertically or horizontally. One half displays a single item or record, and the other half displays a list or provides a datasheet view of multiple records from the underlying data source.

Creating Forms

有几种方法可以在 Access 中创建表单。为此,打开您的数据库并转到 Create tab 。在右上角的“表单”组中,您会看到“表单向导”按钮。

There are a few methods you can use to create forms in Access. For this, open your Database and go to the Create tab. In the Forms group, in the upper right-hand corner you will see the Form Wizard button.

form wizard

单击该按钮以启动表单向导。

Click on that button to launch the Form Wizard.

在此向导中的第一个屏幕上,您可以选择想在表单中显示的字段,并且可以选择从多个表或查询中的字段。

On this first screen in the wizard, you can select fields that you want to display on your form, and you can choose from fields from more than one table or a query.

我们假设我们只需要一个简单的表单,用于输入我们的员工信息。

Let us assume we want to simply have a quick form that we are going to use for data entry for our employee information.

Tables/Queries 下拉列表中,选择 tblEmployees 表。单击双箭头一次移动所有字段。

From Tables/Queries drop-down list, select tblEmployees table. Click on the double arrow to move all the fields at once.

form wizard field

我们只使用此表,然后单击 Next

Let us just leave it with that one table, and click Next.

select job file

表单向导中的下一个屏幕将询问我们希望表单采用何种布局。我们有 columnar, tabular, datasheet and justified 布局。我们在此处选择“列式”布局,然后单击 Next

The following screen in the Form Wizard will ask for the layout that we would like for our form. We have columnar, tabular, datasheet and justified layouts. We will choose the columnar layout here and then click Next.

layout

在以下屏幕中,我们需要为表单指定一个标题。我们将其命名为 frmEmployees

In the following screen, we need to give a title for our form. Let us call it frmEmployees.

为表单指定标题后,您可以打开表单以查看表单的外观,或可以开始向表中输入信息。或者,您可以选择修改表单设计的选项。我们选择第一个选项 open the form to view or enter information ,然后单击 Finish

Once you have given your form a title, you can open the form to see what that form looks like, or you can begin entering information into your table. Or you can choose the option to modify the form’s design. Let us choose the first option to open the form to view or enter information and click Finish.

open form

现在,请看以下屏幕截图。这就是您表单的外观。这是一个单项表单,这意味着一次显示一条记录,在下方您可以看到导航按钮,这告诉我们这是正在显示 9 条记录中的第 1 条。如果您单击该按钮,它将移动到下一条记录。

Now, take a look at the following screenshot. This is what your form looks like. This is a single item form, meaning one record is displayed at a time and further down you can see the navigation buttons, which is telling us that this is displaying the record 1 of 9. If you click on that button then, it will move to the next record.

one record

如果您想跳转到该表单或该表中的最后一条记录,则可以使用位于该右箭头旁边的按钮,一个箭头后边带有一条线,那是最后一条记录按钮。如果您想添加新的员工信息,则转到这些记录的末尾,然后在 9 条记录后,您会看到一个空白表单,您可以在其中开始输入新员工的信息。

If you want to jump to the very last record in that form or that table, you can use the button right beside that right arrow, the arrow with a line after it, that’s the last record button. If you want to add new employee information, go to the end of this records and then after 9 records you will see a blank form where you can begin entering out the new employee’s information.

employee information
new form

这是一个使用表单向导创建表单的示例。现在,让我们关闭此表单并转到“创建”选项卡。现在,我们将使用向导创建稍复杂的表单。单击“表单向导”,这次,我们将从几个不同的表中选择字段。

This is one example of how you can create a form using the Form Wizard. Let us now close this form and go to the Create tab. Now we will create a slightly more complicated form using Wizard. Click the Form Wizard and this time, we will choose fields from a couple of different tables.

在此表单向导中,让我们选择 tblProjects 用于 Tables/Queries ,并选择一些可用的字段,例如 ProjectID、ProjectName、ProjectStart 和 ProjectEnd。这些字段现在将移动到所选字段。

In this Form Wizard, let us choose tblProjects for Tables/Queries, and select a few Available Fields such as ProjectID, ProjectName, ProjectStart, and ProjectEnd. These fields will now move to Selected Fields.

form budget

现在,选择 tblTasks 以使用表/查询,并发送 TaskID、ProjectID、TaskTitle、StartDate、DueDate 和 PercentComplete。单击 Next

Now select tblTasks for Tables/Queries and send over the TaskID, ProjectID, TaskTitle, StartDate, DueDate and PercentComplete. Click Next.

available fields
single form

在这里,我们希望从几个不同的对象中检索数据。我们还可以选择如何安排表单的选项。如果我们想要创建一个扁平的表单,则可以选择按 tblTasks 进行排列,这将创建那个单一的表单,所有字段都以扁平视图进行布局,如上所示。

Here, we want to retrieve data from a couple of different objects. We can also choose from options on how we want to arrange our form. If we want to create a flat form, we can choose to arrange by tblTasks, which will create that single form, with all the fields laid out in flat view as shown above.

但是,如果我们想要基于一对多的关系创建一个分层表单,则可以选择按tblProjects排列数据。

However, if we want to create a hierarchical form based on that one-to-many relationship, we can choose to arrange our data by tblProjects.

subform

在上面的窗口中,我们有一个选项,可以为 tblTasks 包含 subform ,或者我们可以将其制作成一个链接的表单。此链接表单是 tblProjects 将具有一个按钮的位置,该按钮将启动过滤到我们在该基础项目表单中选择的项目的第二个表单。现在,让我们选择 Form with subform(s) ,然后单击 Next

In the above window, we have the option to include a subform for tblTasks, or we can make that a linked form. This linked form is where tblProjects will have a button that will launch that second form filtered to the project that we have selected in that underlying projects form. Let us now select the Form with subform(s), and then click Next.

在以下屏幕中,您可以为子表单选择一个布局。默认情况下选择数据表视图。数据表视图类似于表视图。现在,单击 Next

In the following screen, you can choose a layout for your subform. The Datasheet View gets selected by default. The Datasheet View is similar to Table View. Now, click Next.

datasheet form

在以下屏幕中,您需要为您的表单提供一个名称。输入您想要的名称并单击 Finish

In the following screen, you need to provide a name for your forms. Enter the name you want and click Finish.

frm projects

Access 将为您提供表单的外观预览。在顶部,您可以在主表单上进行控制,它来自我们的 Projects 表。向下滚动,您将看到一个子表单。它就像一个表单中的表单。

Access will give you a preview of what your form looks like. On top, you have the controls on your main form, which is from our Projects table. As you go down, you will see a subform. It’s like a form within a form.

project tables

Multiple Item Form

您可能还希望创建特定类型的表单。为此,您可以单击 More Forms 下拉菜单。

You may also want to create a specific kind of form. For this, you can click on the More Forms drop-down menu.

multiple items

从菜单中,您可以创建一个 Multiple Items 表单、一个 Datasheet 表单、一个 Split 表单,甚至一个 Modal Dialog 表单。这些通常是绑定表单;选择您想要绑定到该表单的对象。这不适用于模态对话框表单。

From the menu, you can create a Multiple Items form, a Datasheet form, a Split form, or even a Modal Dialog form. These are typically bound forms; select the object that you would like to be bound to that form. This does not apply to the Modal Dialog forms.

要创建这种类型的表单,您首先需要在导航窗格中选择对象。让我们在此处选择 tblEmployees

To create this type of form, you will need to select the object in navigation pane first. Let us select tblEmployees here.

employee form

通过单击 More FormsMultiple Items 继续。

Proceed by clicking on More Forms and Multiple Items.

more forms

以上步骤将进一步创建一个多项表单,列出所有员工。

The above step will further create a Multiple Items form, listing out all the employees.

Split Form

这种类型的表单平均分为两半,垂直或水平。一半显示单个项目或记录,另一半显示来自基础数据源的多个记录的列表或数据表视图。

This type of form is divided in equal halves, either vertically or horizontally. One half displays a single item or record, and the other half displays a list or a datasheet view of multiple records from the underlying data source.

现在,让我们在导航窗格中选择 tblEmployees ,然后在 Create 标签中,从“更多表单”菜单中选择 Split Form 选项,您将看到其中一个表单纵向划分的表单。

Let us now select tblEmployees in the navigation pane and then on Create tab. Select Split Form option from More Forms menu and you will see the following form in which the form is divided vertically.

split form