Sei sulla pagina 1di 29

Install Office Sign in India >

Skip to main content


HOME MY OFFICE PRODUCTS SUPPORT IMAGES TEMPLATES STORE

Add a subdatasheet
When two tables have one or more fields in common, you can embed the datasheet from one table in another. An embedded datasheet, which is called a subdatasheet, is useful when you want to view and edit related or joineddata in a table or query.

In this article

Introduction to subdatasheets Open and close a subdatasheet Add a subdatasheet

Introduction to subdatasheets
A subdatasheet is useful when you want to see the information from several data sources in a single datasheet view. For example, in the Northwind sample database, the Orders table has a one-to-many relationship with the Order Details table.

If the Order Details table is added as a subdatasheet in the Orders table, you can view and edit data such as the products included in a specific order (each row) by opening the subdatasheet for that Order.

If you add subdatasheets to your tables, limit the use of these subdatasheets to viewing, and not editing, important business data. If you want to edit data in a table, we recommend that you use forms to edit the data instead of subdatasheets, as data entry errors are more likely to occur in datasheet view if users are not careful to scroll to the correct cell. Also note that adding a subdatasheet to a large table can adversely affect the performance of the table. Microsoft Office Access automatically creates a subdatasheet when you create a table that matches one of the following criteria:

The table is in a one-to-one relationship. The table is the "one" side of a one-to-many relationship, where the table's SubdatasheetName property is set to Auto. A relationship is defined by matching the primary key and the foreign key fields in the related tables. You can also add a subdatasheet to any table, query, or form in a database. In Datasheet view, a form can display only one subdatasheet at a time.
TOP OF PAGE

Open and close a subdatasheet

To determine whether a table, query, or form already has a subdatasheet, open the object in Datasheet view. If an expand indicator (+ sign) is present, then the table, query, or form has a subdatasheet. When the subdatasheet is open, the indicator changes to a - sign. Subdatasheets can be nested in a main subdatasheet for up to eight levels.

To open the subdatasheet, click the plus sign next to the value for which you want to see the records. To close the subdatasheet, click the minus sign.
TIP To expand or collapse all the subdatasheets in an datasheet at the same time, on

the Home tab, in theRecords group, click More. Then select Subdatasheet, and click the option that you want. You can also remove or hide a subdatasheet. For information about how to remove a subdatasheet, see the articleRemove a subdatasheet.
TIP To hide a subdatasheet, open the table in Design View, and then on the Design tab, in

the Show/Hidegroup, click Property Sheet. Find the Subdatasheet Name line, change it to [None], and then save the change.
TOP OF PAGE

Add a subdatasheet
1. In Datasheet view, open the table or query where you want to add the subdatasheet. 2. On the Home tab, in the Records group, click More, point to Subdatasheet, and then click Subdatasheet. 3. In the Insert Subdatasheet dialog box, select the tab (Tables, Queries, or Both) that corresponds to the type of object that you want to insert as a subdatasheet. 4. In the Link Child Fields box, click the field that you want to use as the foreign key or matching field that will provide data for the subdatasheet. 5. In the Link Master Fields box, click the field that you want to use as the primary key or matching field for the main table or query, and then click OK.

For example, if you wanted to create a subdatasheet to view related orders for each Customer record in the Customer table, select the Orders table, in the Link Child Fields box, select Customer ID, and in the Link Master Fields box, select ID.

The values in the Link Child Fields and Link Master Fields boxes create a one-tomany join on the specified fields.
NOTE

6. To display the subdatasheet that you added to your table, query, or form, click the + sign.
NOTE The child (foreign key) field does not appear as a column of the subdatasheet. When you add

a new record in the subdatasheet, Access automatically inserts the primary key value of the selected base-table.
TOP OF PAGE

Did this article help you?


Yes No Not what I was looking for

Applies to: Access 2007 See Also: Watch this: Create a form that contains a subdatasheet

Site DirectoryContact UsSubmit FeedbackLegalTrademarksPrivacy and CookiesAccessibility


2013 Microsoft Corporation. All rights reserved.

TechNet Products IT Resources Downloads Training Support

United States (English) Sign in

Home Library Wiki Learn Gallery Downloads Support Forums Blogs


TechNet Library TechNet Archive Office Office 95 Tips Using Outlook Express to Receive E-mail from Multiple Accounts Performing Two-Dimensional Lookups Tips for Working with Bulleted Text Objects Summarizing Data with Excel's Consolidate...Command

Creating Multitable Forms in MS Access Creating Business Forms Using Word's Table Feature

Creating Multitable Forms in MS Access


16 out of 23 rated this helpful - Rate this topic

Archived content. No warranty is made as to technical accuracy. Content may contain URLs that were valid when origina but now link to sites or pages that no longer exist.
By Susan Harkins Inside Microsoft Office 95 A Publication of The Cobb Group Published June 1997 Sometimes, you'll want to add data to two or more Access tables on the same form. Other times, you'll need to base an entry in one table on data that's stored in another table. In these situations, you'll want to set up and use a multitable form for data entry. For example, Figure A shows a multitable form included with Access' sample Northwind database.

Figure A: The sample Northwind database includes some multitable forms, such as this one.
Although it isn't readily apparent, this Customer Orders form includes information from three tables and is made up of three forms. The top form displays the customer's name, the middle form shows the orders made by that customer, and the bottom form shows the products included in the middle form's selected order. When you choose a different customer, different data appears in the lower two forms. When you choose a different record in the middle form, the bottom form displays data specific to that selected record. If you didn't use a multitable form, you'd have to display a different screen for each combination of company name, order, and order detail. For example, to display the same amount of information shown in Figure Aone customer, five orders, and three products you'd have to display 15 individual screens, each containing one item from each of the three tables. Fortunately, you don't have to go to this trouble, because Access lets you place forms for multiple tables on a single form. In any multitable Access form, you have a main form and one or more subforms. The main form displays data, as any form does, and serves as a container for the subform(s). The subform displays data that for the most part relates to one of the main form's fields. Although

the technique may seem difficult, creating a subform is a snap, as we'll show you in this article. Also, the possibilities are almost endless. Once you master this simple technique, you may find yourself redesigning all your forms.
On This Page

Creating the forms Creating a supplier subform Using the form and subform Creating a product subform Variations

Creating the forms


The best way to show you how to create subforms is by demonstrating the process with an example. Before you begin, you need two tables. The tables must include a common field that you can use to link them. The table's fields must be the same field type and length, although they don't necessarily need to have the same name. For our example, we'll use the Products and Suppliers tables shown in Figure B.

Figure B: We'll create a multitable form for these two tables


Once you've identified the tables you want to use, you should decide which form will be the main form and which will be the subform. Let's suppose you primarily want to view the products but you also want to know each product's supplier. In this case, you'll want to display product data in the main form and supplier data in the subform. Let's begin by creating the product form. In the Database window, choose the Forms tab and click the New button. Highlight the AutoForm: Columnar option, choose the Products table in the dropdown list box at the bottom of the New Form dialog box, and then click OK. Next, click the Save button (), enter the name F_Products in the Save As dialog box, and click OK. At this point, you might want to add a title to the form. To do so, choose the Design View option () on the Form View dropdown list, increase the size of the Form Header band, choose the Label tool () from the Toolbox, drag to draw a text box, and type Pet Care Products in the label box. You can increase the label's font size by selecting the box and choosing a larger number in the Font Size box on the Formatting toolbar. Be sure to save the revised form. You create the subform in the same manner; it becomes a subform only when you place it on a main form. However, you'll want to format it so it will display its information as compactly as possible. To create the supplier form for this example, return to the database window and follow the previous procedure. This time, however, use the text Pet Care Suppliers for the label and save the form as F_Suppliers. Finally, close the supplier form. Top Of Page

Creating a supplier subform


To add F_Suppliers to F_Products, open F_Products in Design view, click the F_Suppliers form in the Database window, and drag it to the main form. The main form will instantly resize to include the subform. (It doesn't matter where you drop the subform right nowyou can move it later.) Next, double-click the main form's title bar to maximize the form so you can position the field controls

and the subform more easily. We positioned the subform to the right of the product table's field controls, as shown in Figure C. We also deleted the supplier form's label.

Figure C: In Design view, position the main form's product data at the left and the subform's supplier data at the right.
To view the form at this point, click Form View () on the Form Design toolbar. As you can see in Figure D, the main form displays the first record in the Products table, while the subform displays the first record in the Suppliers table. If you browse the product records, you'll notice that the records in the subform don't change. That's because you haven't linked the two forms yet. This is your next step.

Figure D: The form displays information from both tables, but the data doesn't appear to be related
Since you want the record displayed in the subform to relate to the record displayed in the main form, you'll need to link the two forms. To do so, return to Design view by clicking Design View on the Form View toolbar. Right-click the supplier subform and choose Properties from the shortcut menu to open the subform's property sheet. To link the subform to the main form, you must link a duplicate fieldgenerally, you link a primary key field in the subform table. In this case, the most obvious link is the Supplier field. So click the property sheet's Data tab and enter the reference Supplier for both the Link Child Fields and the Link Master Fields properties, as we've done in Figure E. At this point, choose Save As/Export from the File menu, select the Within The Current Database As option, and specify the name F_Products&Suppliers. (We're giving the form and subform a new name because we're going to use our basic forms again later.)

Figure E: To link the forms, specify the Supplier field for both the Link Child Fields and Link Master Fields properties.
Top Of Page

Using the form and subform


Now, return to Form view and browse the product records again. This time, the supplier data in the subform will change as you move to a product record that lists a different supplier. For instance, the supplier information is the same for records 1 through 3 in the Products table. As you move to record 4, which has different supplier data, Access will update the supplier data in your subform, as shown in Figure F.

Figure F: Once you link the two forms, Access will display the appropriate supplier data as you browse the product records.
Top Of Page

Creating a product subform


Now let's suppose you want to display a supplier form but you need to display each supplier's products as well. To do so, you'll follow the same process we used earlier. But this time, F_Suppliers will be the primary form and F_Products will be the subform. To create this multitable form, you need to close the F_Products&Suppliers form and restore the Database window. Next, open F_Suppliers in Design view and then drag F_Products from the Database window to F_Suppliers. (Again, it doesn't matter where you drop the form at this point.) Now, maximize F_Suppliers so that it's easier to position the controls. Once you've done this, select the subform labeled Pet Care Products and position it to the right of the supplier field controls. Then, delete the subform's label. To create the links, right-click the subform and choose Properties from the shortcut menu. Assign Supplier as both the Link Child Fields and Link Master Fields properties. Finally, save the form as F_Suppliers&Products using the File menu's Save As/Export command.

Now, click the Form View button's Form View option () on the Form Design toolbar. As you can see in Figure G, the subform's navigational scrollbarwhich displays the record indicator Record: 1 of 1shows that there's only one record for the first supplier, Cats Pajamas. That's because we purchased only one item from this particular supplier.

Figure G: The subform's record indicator tells us that we carry only one of the Cats Pajamas products.
Display the record for the second supplier, Dog Gone Best. When you do, Access displays its first product, Doggie Dandies, in the product subform. But notice that the navigational scrollbar in the subform displays Record: 1 of 2. This means the subform contains a second record. Click the subform's Next button (), and Access displays a second product for Dog Gone BestPuppy Love. If you continue in this manner, you'll find that Got Your Goat! supplies two of our products, Hare Care supplies three, and Kitty Palace supplies just one. Top Of Page

Variations
The technique we've shown you in this article barely scratches the surface of designing forms that contain subforms. For example, Access lets you make a subform invisible if its corresponding field in the main form is empty. In addition, you can design pop-up subforms that appear only when your cursor is on the related field in the main form. As the Northwind form shown in Figure A demonstrates, you can also link a subform to another subform that's linked to the main form. If you'd like to explore some other possibilities, open the forms in Access' sample databases in Design view and then look at the forms' and subforms' properties sheets. The Data and Event tabs are particularly useful for learning how to relate information between a form and its subforms. In addition to the Northwind database, which is stored in the Access\Samples directory, you can make Access create databases with sample data by choosing New Database from the File menu, clicking the Databases tab, and selecting a sample file. The Database Wizard will lead you through the rest of the process of creating the sample database. Susan Harkins is editor-in-chief of The Cobb Group's Inside Microsoft Access The article entitled "Creating Multitable Forms in Access" was originally published in Inside Microsoft Office 95, June 1997. Copyright 1997, The Cobb Group, 9420 Bunson Parkway, Louisville, KY 40220. All rights reserved. For subscription information, call the Cobb Group at 1-800-223-8720. We at Microsoft Corporation hope that the information in this work is valuable to you. Your use of the information contained in this work, however, is at your sole risk. All information in this work is provided "as is," without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement , and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Microsoft Corporation. Microsoft Corporation shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages. Top Of Page

Did you find this helpful?

Yes

No

2013 Microsoft Manage Your Profile

Newsletter | Contact Us | Privacy Statement | Terms of Use | Trademarks |

Site Feedback

Lookup Tables in Access


When we say that a table is a lookup table for another main table, it means that the lookup table contains values that will be used as the contents of a field located in the main table. Usually the lookup table has at least two fields Id and Description. The main table stores only the values from the Id field, but since there is a relationship between the lookup and the main table, the value of the associated Description field is also associated with the record in the main table. On the level of the user interface, lookup tables are often implemented as list boxes or combo boxes.

Products Services Text Market Book of Knowledge (articles & whitepapers) SQL Server 2005 Stored Procedure Programming in T-SQL and .NET, 3rd Ed. SQL Server 2000 Stored Procedure and XML Programming, 2nd Ed.

Linking tables
We can demonstrate this concept using tables which contain information about companies and cities. First, we will link the tables on the table level. The link will be implemented as a list box on the user interface level. Create following tables: CITY CityId CityName identification number of a city name of a city

COMPANY SQL Server 2000 Stored Procedure Programming e-Business News SQL Server News About Us Contact Us Join Us Links Search
2003 - Trigon Blue Inc. All rights reserved.

CompanyId CompanyName CityId

identification number of a company name of a company identification number of a city

The CityId field links the tables. They are in a 1:n relationship, which means that: a company can be situated only in one city, but a city can have many companies. A record in the Company table has only one record in the table City, but a record in the City table can have more than one record in the Company table. It is possible to display a list box to select a city instead of a text box in which to enter a CityId into the Company table. Behind the scene Access will operate with the CityId field. An identifier, which corresponds to a selected city, will be stored in the CityId field of the Company table. Another result of such a link is that the user is prevented from entering a value which does not exist in the City table. You can accomplish this feat in following way: First, you create the City table in the standard way:

Note that the Data Type of the CityId field in this table is set to AutoNumber. When creating the Company table, you should include the CityId field as well. Usually, we would set the Data Type to Number (Long Integer). That type corresponds to AutoNumber. In this case we will select another one.

Select Lookup Wizard from the Data Type drop-down list.

Since we want to use values from a lookup table, select the first option, then click Next. Select the City table as the source of values for your lookup column then click Next.

Select the fields that will appear in the lookup (list box).

Click Next. The Lookup Wizard shows your lookup column.

Usually, you do not need to display the key column (CityId). Click Next to continue. Name the lookup column and click Finish.

If you open the table definition, you will notice that the CityId field's properties are set as follows:

Row source type Row source

table/query SQL query The property tells Microsoft Access which column values to use as the value of the control. If the control is bound to a field, the value in the column specified by the bound column property is stored in the field named in the Control Source property. specify the width of each column in a multiple-column list box.

Bound column

Column widths

It is also interesting to see how a lookup table is affected by linking. Open the City table and notice the '+' boxes along the left border. When you click on a '+' in one record, Access opens the section of the main table with the records associated with the selected lookup record.

Linking forms

Tables in Access can also be linked on the form level. We can do this on top of linked tables, but it isn't necessary. Forms can be linked even when the tables are not linked. In fact, that is what we recommend. It is better to link forms rather than tables. Create the City and Company tables as you would usually. Now we want to use forms to view and edit the content of these tables. We should have a list box to display cities on the form that displays Company information. Again, users will be prevented from adding a city for which there is not already a record in the City table. Create a form to show the Company table in following manner: In Design mode, put text box controls CompanyId and CompanyName and a combo box to show CityName from City table.

As soon as you create the combo, Access opens the Combo Box Wizard. Specify that the combo box will look up the values from a table. Click Next.

The wizard opens a window where you select a table to provide the values for your combo box. Click Next.

Select the fields that contain the values you want included in your combo box. Click Next.

The wizard displays a window with a preview of the combo box. Usually, you will not display the key column as a part of your combo. You can also adjust the width of the column(s). Click Next.

The wizard prompts you for the field that this column will be bound to. Select CityId and then click Next.

Name the combo box and then click Finish.

Now, on your form you have a combo box.

If you view the Properties of the combo box, you will notice that the wizard has changed the following properties: Specify what data appears in a control (CityId) table/query SQL query The property tells Microsoft Access which column values to use as the value of the control. If the control is bound to a field, the value in the column specified by the bound column property is stored in the field named in the Control Source property. width of each column in a multiplecolumn list box To hide first column set its width to zero (0";1").

Control source Row source type Row source

Bound column

Column widths

When you activate the new form, you see the following:

When you add a new record, it is enough to type the first character of the name of the city (if the record is in table City), or to select CityName in combo box and it will be added.

Linking forms manually


This whole process can be performed manually as well. You need to create a form that shows the Company table and add text boxes for all fields. Then you need to change the text box for displaying CityName field into a list box. Right click the field and select Change Type from the menu. Select List Box. Then view the properties of the CityName field. Change the following parameters: Property Row source ColumnCount Description to define rule how to load combo box or list box. New value Select CityId, CityName from City

specifies a number of columns displayed in a 2 list box or in the list box portion of a combo box specifies the width of each column in a 0";1" multiple-column combo box or list box. You can also use this property to hide one or more columns. specifies what data appears in a control which column values to use as the value of the control. If the control is bound to a field, the value in the column specified by the bound column property is stored in the field named in the Control Source property CityId 1

ColumnWidths

Control Source Bound column

After everything is set, the combo box displays only CityName, but your program will use CityId behind the scenes.

Home | Products | Services | Book of Knowledge | e-Business News | SQL Server News About Us | Contact Us | Join Us | Links | Search

Instructions
1.

1
Select the "Create" tab and choose "Report Wizard" from the "Reports" group.

o o

2
Select the table or query you want to use for the invoice.
Sponsored Links

Password Recovery Tool


Store Online Passwords Securely. Get Dashlane Today Free! Dashlane.com

3
Highlight the field you want to add from "Available Fields" using the single arrow. To move all the fields, click the double-arrow. To insert fields from another table/query, repeat steps two and three. Then click "Next."

4
Select the order you want the fields to appear, then click the right arrow.

5
Click "Next" to choose a sort order or skip this step. To choose a sorting order, select the first field you want to sort from the drop-down. To switch to descending order, click "Ascending" and the button will change to "Descending." You can sort up to four fields.

6
Click "Next" when you are finished.

7
Pick a layout for the invoice, then click "Next."

8
Choose a style and click "Next."

9
Type in a report name for the invoice and select "Modify the report's design." Then click "Finish." You will be directed to "Design" view.

10

Double-click the button to the left of the "Detail" section on the invoice. The "Section: Detail" dialog box opens. o

11
Go to the "Force New Page" text field under the "Format" tab. Choose "After Section" from the drop-down list and close the dialog box.

12
Click the "Layout" or "Print Preview" view to display the invoice.
Read more: How to Create a Report in Microsoft Access 2007 With One Invoice Per Page | eHow.com http://www.ehow.com/how_6896344_create-2007-one-invoice-per.html#ixzz2PrxkcW2F

How to Use Microsoft Access for Invoicing


By Emily Ediger, eHow Contributor , last updated April 17, 2012

Print this article

Keep track of your invoices using Access tables and reports.

Keep track of your business transactions with a Microsoft Access database. Using tables and reports, you can log hours, wages and customer information, and display them with an invoice. Instead of manually creating a custom invoice each time you need to bill a client, Access can automatically

generate invoices that you can view, print or email. The report you create will contain all invoices, so you won't have to search for documents whenever you need to review previous invoices.

Other People Are Reading

How to Create an Organizer Using Microsoft Access

1.

How to Create an Invoice Email

Instructions
o

1
Create a "Customer" table that contains all of your customer or client information by clicking the "Table Design" button on the "Create" tab of the ribbon at the top of the page. The "Table Design" tool allows you to create a table from a blank template. Include fields for your customer's name, contact information and unique ID number.

2
Create an "Invoice" table that contains information regarding each business transaction. Add fields for location, cost and other necessary details. To assign a customer to each transaction, add a "Customer Name" field, select "Lookup Wizard" as a data type and link to the "Customer" table.
Sponsored Links

QuickBooks Online
QuickBooks Online is now in India. A Must Software for SMEs. Try Free! quickbooksonline.in

3
Select the customer's name field in the "Lookup Wizard" to display the names in the "Customer Name" field of your "Invoice" table. This step creates a relationship between the "Customer" and "Invoice" tables, and reduces data redundancy. Instead of typing in the customer's contact information for each business transaction, you store the information just once in the "Customer" table.

4
Create an "Invoice" report by selecting the "Report Wizard" button from the "Create" tab on the ribbon. Select all of your fields in the "Invoice" table and customer contact information from the "Customers" table to display on the report. Select "Modify the Report's Design" on the last screen of the "Report Wizard" to change the layout of the report.

5
Add a page header and footer, and include your company contact information, logo and invoice terms. Increase the size of the report's detail section to display only one transaction per page. Add subtotals and totals by placing calculated controls on your report and inputting an expression such as "=[BillableHours]*[Wage]."

6
Save your report and name it with a descriptive title. Switch to "Print Preview" view to review the content and layout of your report.
Sponsored Links

Read more: How to Use Microsoft Access for Invoicing | eHow.com http://www.ehow.com/how_8596642_use-microsoftaccess-invoicing.html#ixzz2Pry0s3IJ

Potrebbero piacerti anche