Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M...

28
Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web browser, right-click and choose “Fu ll Screen” before proceeding. Click mouse or press space bar to continue. esentation was prepared by Professor Steve Ross, with the advice of other MIS Faculty, for use in MIS Classes at Western Washington Un contact Dr. Ross for permission to use in other settings..

Transcript of Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M...

Page 1: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Entering Data in One of the Independent Entity Tables and the Associative Entity Table

of a M:M Relationship*

If you came to this presentation via a web browser,

right-click and choose “Full Screen” before proceeding.

Click mouse or press space bar to continue.

• This presentation was prepared by Professor Steve Ross, with the advice of other MIS Faculty, for use in MIS Classes at Western Washington University. Please contact Dr. Ross for permission to use in other settings..

Page 2: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

The Goal: Edit Buildings and Assignments to the Buildings

Page 3: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

tblAssignmentBuildingID

WorkerID

StartDate

tblBuildingBuildingID

Address

City

State

Zip

Description

Status

ManagerID

BuildingType

tblWorkerWorkerID

LastName

FirstName

MidName

AnnualPayIn1000

RankID

SupervisorID

DepartmentID

MailCode

The Challenge

• The data comes from two different tables– tblBuilding– tblAssignment– You cannot edit data

from two tables on the same form.

Page 4: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

tblAssignmentBuildingID

WorkerID

StartDate

tblBuildingBuildingID

Address

City

State

Zip

Description

Status

ManagerID

BuildingType

tblWorkerWorkerID

LastName

FirstName

MidName

AnnualPayIn1000

RankID

SupervisorID

DepartmentID

MailCode

The Solution

• In a 1:M relationship, represent … – the 1-side as the main

form– The M-side as the

subformRecord Source for

the main form

Record Source for

the subform

Page 5: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 1 – Source Data

• The standard for this course is to use a view as the Record Source of each form. For any form that enables the user to edit data, the view must be based on a single table only.

• Therefore Step 1 is to create a view for each form.– vueFrmBuilding and vueSfrAssignment contain all

fields of their respective tables

Page 6: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 1a – Source Data

Determine how each field from vueFrmBuilding will appear on the “1-side” form.

(Note: “controls” are objects on the form, such as labels, textboxes, buttons and combo boxes.)

Field Editable Control format

Constraints

BuildingID No Read only text

Address Yes Text box

City Yes Text box

State Yes Text box

Zip Yes Text box

Description Yes Text box

Status Yes Text box

ManagerID Yes Combo box

FK to tblWorker

BuildingType Yes Text box

Page 7: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 1b – Source Data

Do the same for vueSfrAssignment – the “M-side” view

* The foreign key in the subform, vueSfrAssignment.BuildingID, always matches the value of the parent form linking field (vueFrmBuilding.BuildingID) on the main form.

Therefore, an editable or visible control is not needed on the subform for the FK field.

Field Editable Control format Constraints

BuildingID No No control needed* FK to tblBuilding

WorkerID Yes Combo FK to tblWorker

StartDate Yes Text box

Page 8: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Just one more slight complication: tblAssignment does not contain any Worker Names, it contains WorkerIDs. How do we show names instead?

15

37

Page 9: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

The Complication: the Worker is a number (WorkerID) in the tblAssignment

The Solution: Use a combo box to look up and show the Worker Name corresponding to the WorkerID

Page 10: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Standard Form Heading

Step 2 – Layout

• Create a draft view of the form, giving approximate placement and type of controls for each data item

I usually do

this by hand,

not in a graphic

program such

as this

BuildingID (read only, no label)

Address:

City:

State: Zip:

Description:

Status:

Manager: Person list combo box

Address

City

Description

Status

State Zip

AssignmentsPerson Start Date

These will be text boxes bound to the

relevant fields

Person list combo box

Person list combo box

Person list combo box

StartDate

StartDate

StartDate

These will be combo boxes, bound to the relevant fields but displaying

data from the related tables

Page 11: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3a – Create Version 1of the Main Form

• Create the main form– Use the “1-side” view created in Step 1 (vueFrmBuilding)

as the record source

– Add all desired fields to the form

Page 12: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3b – Add the SubformThere are multiple ways to create a subform.

1.From Scratch•Build and save a form to use as the subform. •Drag the subform from the Forms object window into the Details area of the main form•Set ….

– The Link Master Fields and – The Link Child Fields

… to the appropriate PK and FK (e.g. BuildingID)

Page 13: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3b – Add the Subform2. With the subform button and wizard

Use the “M-side” view as the record source

Notice that the PK and FK fields are the link between the main form and the subform.–“Parent” or “Master” (PK) field on the left

–“Child” (FK) field on the right

Page 14: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3b – About the Subform Control

Illustrated below is …•A subform (It’s everything inside the orange box)•A subform control (It is the orange box)

– The subform control manages the link between the main form and the subform

Page 15: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3b – About the Subform Control

The Subfo

rm C

ontrol is

selected (o

range b

ox)

The Subfo

rm is

selected

(notic

e the b

lack dot)

Page 16: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3b – About the Subform Control

The Data properties tab shows … •the Link Master Fields and •the Link Child Fields

The linkage is good

The linkage is broken

Page 17: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3c – Subform LayoutNormally, you will have to do additional formatting of the subform.

Page 18: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3c – Subform LayoutSet the subform Default View to Continuous Forms.

Page 19: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3c – Layout Comparison

Side-by-side Comparison Efficient Wasteful

Neat MessyData

View

Page 20: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 3c – Layout Comparison

Side-by-side Comparison Efficient Wasteful

Neat Messy

Data

View

Page 21: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 4a – Fine Tuning, Main Form

• Convert text boxes to combo boxes or other controls as necessary*

* See this presentation for discussion of technique.

Page 22: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 4b – Fine Tuning, Subform

• Open the subform in design view• Convert text boxes to combo

boxes or other controls as necessary

• Change the Default View to Continuous Forms– Set Dividing Lines

and Record Selectors to “yes”

Important settings

Page 23: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 4c – Finish the Forms

• Apply check constraints and other properties to controls.• Once controls are set, apply other design standards.*

* The form illustrated met all MIS 421 design standards when it was created.Subsequent changes to the standards may have occurred.

Page 24: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Trouble Shooting

Common Problems

•Do all the records from the M-side table show in the subform … no matter what record is on the main form? See “Broken Linkage” slide below.

•Does the Combo Box for a FK field look like it is set up correctly, but you still cannot enter or change the Combo Box entry? See “Too Many Tables in Your View” slide below.

Page 25: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Trouble ShootingBroken Linage

• Sometimes the linkage is broken. Building 1 actually has only two assignments, but all assignments are appearing on the subform.

Page 26: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Trouble ShootingToo Many Tables in Your View

• Sometimes the Combo Box does not allow you to change the value in the Combo Box – even though the Combo Box appears to be set up correctly. – The most likely cause is that the view for the Form or the view for the Subform is

based on more than one table. There should be just one table supporting the Main Form and one supporting the Subform. Delete unneeded tables from the view.

Page 27: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

The Chicken or the Egg• You are asked to enter this new information.

– New Building: • Address 123 Cherry Lane• City: Demingway• State: WA• ZIP: 99999

– New Worker:• Name: Joe Blaineless

– New Assignment:• Joe is assigned to the new Demingway building on Jan 1, 20xx

• Which data requires an additional form?• Which data must be entered first? Last?

Page 28: Entering Data in One of the Independent Entity Tables and the Associative Entity Table of a M:M Relationship* If you came to this presentation via a web.

Step 5 – Quality Assurance

• Can the user change data in an existing record– in the “1-side” view?– in the “M-side” view?

• Can the user enter new records – in the “1-side” view?– in the “M-side” view?

• Are all constraints working properly? (Test the limits.)

• Have all Design Standards been met?