Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mark Dixon Page 1 05 – Database Design: Sub-forms.

Similar presentations


Presentation on theme: "Mark Dixon Page 1 05 – Database Design: Sub-forms."— Presentation transcript:

1 Mark Dixon Page 1 05 – Database Design: Sub-forms

2 Mark Dixon Page 2 Session Aims & Objectives Aims –To allow easier data entry from multiple tables using forms Objectives, by end of this week’s sessions, you should be able to: –create a sub form that allows data entry into a related table

3 Mark Dixon Page 3 What is a Main and Subform? In a One to Many relationship: –Main form displays the ‘One’ record Master table (or Query) –Subform displays the ‘Many’ records Child or Details table (or Query) Customer Order Details –Main contains Customers, Customer Orders and Order tables –Subform contains Order Lines and Products tables

4 Mark Dixon Page 4 Sub-forms: Why? Usually used for tables with a One-to-Many relationship Need to enter several records in one table link to one in another Wish to view all records from one table which are related to one in another

5 Mark Dixon Page 5 Sub-forms: Why? Creation of coherent data –Ensures orders are ‘linked’ to the correct customer View data linked to a record –Check current orders –Check back orders

6 Mark Dixon Page 6 How do they work? Main form produced from a table or query –Displays data from the ‘one’ side of relationship Subform produced from different table or query –Displays data from the ‘many’ side of relationship Subform inserted into Main form –Subform only displays records linked to Main –All data available form that one-to-many

7 Mark Dixon Page 7 Creating Main and Subforms… Create query for Main form Create query for Subform(s) Create form layouts: –Main –Subform(s) Insert Subform(s) into Main form Link Forms Final format to create desired view

8 Mark Dixon Page 8 An Example… ACME Customer Order Details Select Customer –View items to send –Used by warehouse to pick/send orders

9 Mark Dixon Page 9 Creating Main Form Query… Create query to join Customers, Customer Orders and Orders

10 Mark Dixon Page 10 Creating Subform Query… Create query to join Order Lines and Products

11 Mark Dixon Page 11 Creating the Subform… Open the form Wizard Select the Sub Form Query from ‘Table/Query’ Use all fields Select ‘by Order Line’

12 Mark Dixon Page 12 Creating the Subform… Select ‘Datasheet’ Select ‘Standard View’ Open in ‘Design View’ Field label should be meaningful: –Change Caption of Label –Change Name of Field

13 Mark Dixon Page 13 Creating the Subform… Change field order to make logical sequence Change order in Design View Change Tab Order –Right Click Available ‘Areas’ Fields and current order

14 Mark Dixon Page 14 Creating the Subform… Hide unneeded columns –Order ID is not needed in Subform as it is stated in Main Form In ‘View’ right click on the column Select ‘Hide Columns’ Save form

15 Mark Dixon Page 15 Creating the Subform… Final form will look like this –Field titles and order are as desired –All Order Lines records are shown as it is not yet linked to the Main Form

16 Mark Dixon Page 16 Creating the Main form… Open the form Wizard Select the Main Form Query form ‘Table/Query’ Use all Fields Select ‘by Orders’ –As we wish to view the orders

17 Mark Dixon Page 17 Creating the Main form… Select ‘Column’ layout Select ‘Standard’ style Save form as “ Order Details ” Open in ‘Design View’ Format fields and labels

18 Mark Dixon Page 18 Linking Main and Sub Extend the main forms detail area Move form so you can see the objects window Select and drag the sub form in and drop Select the subform and open properties

19 Mark Dixon Page 19 Creating the Main form… Add header to ‘explain’ form Add label to ‘explain’ Subform With Main and Subform Linked only records that are linked will be shown Save Form

20 Mark Dixon Page 20 Result of Main and Subform…

21 Mark Dixon Page 21 Tutorial Exercise: Music Task 1: Use a form and sub-form to enter data for Tracks and Artists


Download ppt "Mark Dixon Page 1 05 – Database Design: Sub-forms."

Similar presentations


Ads by Google