Cách tạo main sub form trong access 2010

When you are working with relational data (related data that is stored in separate tables), you often need khổng lồ view multiple tables or queries on the same khung. For example, you might want lớn see customer data from one table và information about customer orders from another table at the same time. Subforms are a convenient tool for doing this, and Access provides several ways khổng lồ help you create subforms quickly.

Bạn đang xem: Cách tạo main sub form trong access 2010

What vày you want to do?

Learn about subforms

A subsize is a size that is inserted in another form. The primary size is called the main khung, & the khung that is enclosed in khung is called the subform. A form/subform combination is sometimes referred to as a hierarchical form, a master/detail khung, or a parent/child form.

Subforms are especially effective sầu when you want khổng lồ show data from tables or queries that have sầu a one-to-many relationship. A one-to-many relationship is an association between two tables in which the primary key value of each record in the primary table corresponds lớn the value in the matching field or fields of many records in the related table. For example, you can create a form that displays employee data, & contains a subkhung that displays each employee"s orders. The data in the Employees table is the "one" side of the relationship. The data in the Orders table is the "many" side of the relationship — each employee can have more than one order.

*

1. The main form shows data from the "one" side of the relationship.

2. The subform shows data from the "many" side of the relationship.

The main form and subsize in this kind of khung are linked so that the subkhung displays only records that are related khổng lồ the current record in the main size. For example, when the main khung displays Nancy Freehafer"s information, the subform displays only her orders. If the size và subkhung were unlinked, the subsize would display all the orders, not just Nancy"s.

The following table defines some of the terminology that is associated with subforms. Access will handle most of the details if you use the procedures in this article, but it is helpful lớn know what is occurring behind the scenes if you need to make modifications later.

Term

Definition

Subkhung control

The control that embeds a khung into lớn a size. You can think of the subkhung control as a "view" of another object in your database, whether it is another size, a table, or a query. The subsize control provides properties which allow you khổng lồ link the data displayed in the control lớn the data on the main khung.

Source Object property

The property of the subkhung control that determines what object is displayed in the control.

Datasheet

A simple display of data in rows and columns, much lượt thích a spreadsheet. The subsize control displays a datasheet when its source object is a table or query, or when its source object is a khung whose Default View property is phối lớn Datasheet. In these cases, the subsize is sometimes referred lớn as a datasheet or subdatasheet instead of as a subform.

Link Child Fields property

The property of the subkhung control that specifies which field or fields in the subform link the subform to lớn the main size.

Link Master Fields property

The property of the subform control that specifies which field or fields on the main form link the main khung lớn the subform.


Notes: 

For best results, establish table relationships before following the procedures in this article. This enables Access lớn automatically create the links between subforms and main forms. To view, add, or modify relationships between the tables in your database, on the Database Tools tab, in the Show/Hide group, cliông xã Relationships.

When a subsize control has a khung as its source object, it contains the fields that you place on the khung, & it can be viewed as a single size, continuous size, or datasheet. One advantage of basing a subkhung on a khung object is that you can add calculated fields to the subform, such as * .


Top of Page

Create or add a subform

Use the following table to determine which procedure is most appropriate for your situation.

Scenario

Recommended procedure

You want Access to lớn create both a main khung and a subkhung, & to lớn link the subkhung to the main form.

Create a khung that contains a subsize by using the Form Wizard

You want khổng lồ use an existing form as the main khung, but you want Access to create a new subsize & add it lớn the main form.

Add one or more subforms lớn an existing khung by using the Subform Wizard

You want to use an existing khung as the main form, và you want lớn add one or more existing forms khổng lồ that size as subforms.

Create a subkhung by dragging one size onto lớn another

Create a size that contains a subkhung by using the Form Wizard

This procedure creates a new form và subsize combination by using the Form Wizard. This is also the quickest way to get started if you have not already created the forms that you want lớn use as the main form or the subform.

On the Create tab, in the Forms group, cliông xã Form Wizard

On the first page of the wizard, in the Tables/Queries drop-down các mục, select a table or query. For this example, lớn create an Employees form that displays orders for each employee in a subform, we will select Table: Employees (the "one" side of the one-to-many relationship).


Double-click the fields that you want to lớn include from this table or query.

On the same page of the wizard, in the Tables/Queries drop-down danh mục, select another table or query from the các mục. For this example, we will select the Orders table (the "many" side of the one-to-many relationship).

Double-cliông chồng the fields that you want lớn include from this table or query.

When you cliông xã Next, assuming that you mix up the relationships correctly before you started the wizard, the wizard asks How do you want to lớn view your data? — that is, by which table or query. Select the table on the "one" side of the one-to-many relationship. For this example, to create the Employees size, we will cliông xã by Employees. The wizard displays a small diagram of a khung. The page should resemble the following illustration:

*

The box in the lower portion of the form diagram represents the subkhung.


Note: If the wizard does not ask How bởi you want khổng lồ view your data?, that means that Access did not detect a one-to-many relationship between the tables or queries that you selected. The wizard will continue, but Access will not add a subform lớn the size. You might want lớn clichồng Cancel and examine your table relationships before you continue.


At the bottom of the wizard page, select Form with subform(s), and then cliông xã Next.

On the What layout would you like for your subform? page, cliông xã the layout option that you want, và then click Next. Both layout styles arrange the subform data in rows & columns, but a tabular layout is more customizable. You can add color, graphics, and other formatting elements to a tabular subkhung, whereas a datasheet is more compact, lượt thích the datasheet view of a table.

On the next page of the wizard, select a formatting style for the form, & then click Next. If you chose Tabular on the previous page, the formatting style you choose will also be applied khổng lồ the subsize.

On the last page of the wizard, type the titles that you want for the forms. Access names the forms based on the titles that you type, và labels the subsize based on the title that you type for the subform.

Specify whether you want to open the khung in Form view, so that you can view or enter information, or in Design view, so that you can modify its kiến thiết, and then click Finish.

Access creates two forms — one for the main form that contains the subsize control, và one for the subsize itself.

Top of Page

Add one or more subforms to an existing khung by using the SubForm Wizard

Use this procedure lớn add one or more subforms lớn an existing khung. For each subsize, you can choose to have sầu Access create a new size or use an existing khung as the subsize.

Right-cliông xã the existing form in the Navigation Pane, và then click Design View.

Xem thêm: Mối Quan Hệ Giữa Nhiệt Độ Không Khí Và Độ Ẩm !, Mối Quan Hệ Giữa Nhiệt Độ Không Khí Và Độ Ẩm

On the Design tab, in the Controls group, cliông chồng the down-arrow to lớn display the Controls gallery, and ensure that Use Control Wizards is selected.

On the Design tab, in the Controls group, clichồng the Subform/Subreport button.

Cliông xã on the form where you want to lớn place the subsize.

Follow the directions in the wizard.

When you click Finish, Access adds a subform control khổng lồ your size. If you chose to lớn have sầu Access create a new size for the subkhung instead of using an existing size, Access creates the new size object and adds it khổng lồ the Navigation Pane.

Create a subform by dragging one form onkhổng lồ another

Use this procedure if you want to lớn use an existing size as a main khung, và you want to add one or more existing forms lớn that form as subforms.

In the Navigation Pane, right-cliông chồng the form that you want to lớn use as the main size, & then cliông xã Layout View.

Drag the khung that you want khổng lồ use as the subkhung from the Navigation Pane onto the main khung.

Access adds a subsize control to lớn the main form & binds the control to the form that you dragged from the Navigation Pane. Access also tries lớn liên kết the subsize lớn the main khung, based on the relationships that have been defined in your database.

Repeat this step khổng lồ add any additional subforms lớn the main form.

To verify that the linking was successful, on the Home tab, in the Views group, clichồng View, cliông chồng Form View, và then use the main form"s record selector lớn advance through several records. If the subform filters itself correctly for each employee, then the procedure is complete.

If the previous test does not work, Access was unable khổng lồ determine how lớn liên kết the subsize lớn the main khung, and the Link Child Fields & Link Master Fields properties of the subkhung control are blank. You must phối these properties manually by doing the following:

Right-clichồng the main form in the Navigation Pane, và then click Design View.

Cliông xã the subform control one time to lớn select it.

If the Property Sheet task pane is not displayed, press F4 khổng lồ display it.

In the Property Sheet, cliông chồng the Data tab.

Cliông xã the Build button

*
next khổng lồ the Link Child Fields property box.

The Subkhung Field Linker dialog box appears.

In the Master FieldsChild Fields drop-down lists, select the fields that you want khổng lồ link the forms with, và then click OK. If you are not sure which fields to use, cliông xã Suggest to lớn have Access try to determine the linking fields.


Tip: If you bởi vì not see the field that you want to lớn use khổng lồ links the forms, you might need to lớn edit the record source of the master khung or child size lớn help make sure that the linking field is in it. For example, if the khung is based on a query, you should make sure that the linking field is present in the query results.


Save the main size, switch khổng lồ Form view, và then verify that the form works as expected.

xuất hiện a subform in a new window in Design view

If you want khổng lồ make thiết kế changes to a subform while you are working on its main form in Design view, you can open the subform in its own window:

Clichồng the subsize khổng lồ select it.

On the Design tab, in the Tools group, cliông chồng Subsize in New Window.

Top of Page

Change the mặc định view of a subform

When you add a subkhung lớn a khung, the subform/subreport control displays the subsize according to the subform’s Default View property. This property can be mix lớn the following values:

Single Form

Continuous Forms

Datasheet

Split Form

When you first create a subform, this property may be phối khổng lồ Continuous Forms or perhaps Single Form. However, if you set the Default View property of a subkhung khổng lồ Datasheet, then the subsize will display as a datasheet on the main form.

To phối the Default View property of a subform:

Cthảm bại any open objects.

In the Navigation Pane, right-cliông chồng the subsize and then cliông xã Design View.

If the Property Sheet is not already displayed, press F4 lớn display it.

In the drop-down danh sách at the top of the Property Sheet, make sure Form is selected.

On the Format tab of the Property Sheet, phối the Default View property lớn the view you want to lớn use.


Note: If the view you want lớn use is not in the danh mục, make sure the “Allow…View” property for the view is set to Yes. For example, if you want khổng lồ specify Datasheet as the mặc định view for the khung, make sure that the Allow Datasheet View property is set khổng lồ Yes.


Save and cthua the subkhung, and then open the main size to kiểm tra the results.

Top of Page

Add related data lớn a form without creating a subform

It is not always necessary to create a separate size object khổng lồ display related data. For example, if you are working on a size in Layout view or Design view & you drag a table or query from the Navigation Pane lớn the form, Access creates a subform/subreport control that displays the data in that object. The object’s Default View property determines how the data is displayed. Usually, this is set to Datasheet view, but you can also mix the Default View property of a table or query lớn Single Form, Split Form, or Continuous Forms, giving you more flexibility in displaying related data on forms.

Xem thêm: Top 10 Bài Văn Tả Cảnh Mùa Hè, Bài Văn Tả Cảnh Mùa Hè Lớp 5 Hay Nhất


Note: Changing the Default View property for a table or query determines how it is displayed whenever it is opened, whether you open it from the Navigation Pane or view it in a subform/subreport control. Because changing the view settings for a table can sometimes cause confusion when opening the table from the Navigation Pane, we recommend using a query for this procedure instead of a table.


Chuyên mục: Game online