Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To...

28
Mark Dixon Page 1 06 – Expression Builder
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    222
  • download

    2

Transcript of Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To...

Page 1: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 1

06 – Expression Builder

Page 2: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 2

Session Aims & Objectives• Aims

– To use expressions to perform more complex calculations in forms

• Objectives,by end of this week’s sessions, you should be able to:

– create an expression that calculates a value using existing table fields

Page 3: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 3

What is an Expression…• A set of Data and Operators

• Used to select data in a query– "PT0010" Or "PT0011" Or "PT0012"

• Used to calculate a value– [Unit Price]*[Quantity]

Page 4: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 4

When do we use them…

• In queries– Select records with multiple values– Select records on a calculated value

•[Order Date] = Now()•Sum([Unit Price]*[Quantity]) >= 100

• In Reports or Form– Calculate values that are not stored

• Order Price = Sum([Unit Price]*[Quantity])

• VAT = Order Price*0.175

Page 5: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 5

Why use Expressions…• Only store values that cannot be calculated from

others– Wish to use these values– Use additional values for Reports

• Group Summary• Report Summary

• Allows more flexibility when asking ‘questions’– Specify more values in a query– Find range

• Less than• Greater than• etc.

Page 6: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 6

Expression Builder…• Let Access do the hard work

• Built in Expression Builder– Allow easy selection of values– Combination with operators

• Simple +, -, *, /• More complex Sum, LIKE, And, Or, Not

Icon

Page 7: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 7

Expression Builder…

Expression

Basic Operators

Objects

Fields/Groups

Values/Operators

Page 8: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 8

Expression Builder…

‘Object’ currently in

‘Objects’in Database

General Function

Constant Values

Basic Operators(AND, OR, NOT, MOD<=, =)

Commonly used Expression(Page N of M, Date/Time)

Page 9: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 9

Building Expressions…• Select vales from the windows

– Use ‘Current Object’ for values on the query/form etc being worked on

– When using multiple objects• Select type from first window• ‘Loaded’ from the expanded list• ‘Values’ from other windows

Page 10: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 10

Uses for Expressions…• Calculate a value in a

form– Sum of all the order

lines– Sum of an order– VAT– Grand Total

• Selecting records from a Query– When stock falls below

a certain level– All orders placed in the

last month

Page 11: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 11

An Example…• Customer Order Form

– Similar to the Order details form from last lecture

– Views cost of order as well

Page 12: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 12

An Example…• Build the Order Details Main and Sub Order

Form from lecture 5– Include the cost information as well

• Products - Unit Price

Page 13: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 13

New Sub Form Query…

• Main form query same as last weeks lecture

Page 14: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 14

New Sub Form…

• Need to add line price– Extend form (left)– Add new Text Box (Details) and Label (Header)

Page 15: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 15

Calculating Totals…

• Text box is Unbound– Open Properties– Set Name– Select Control Source– Click …

Page 16: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 16

Calculating Totals…• Expression Builder will

launch

– Must multiple [Quantity] and [Unit Price]

– Select values from the relevant list object

– Use buttons for simple operators

Page 17: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 17

Calculating Totals…

– Expression now displayed in the Control Source of the text box

– Also in text of box

• Need to calculate total for all lines– This value will be

stored in the footer

– Extend footer and add text box and label

– Rename– Set control source to

Sum the Total values• =Sum([Quantity][Unit Price])

Page 18: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 18

Final Sub Form…

Page 19: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 19

Creating Main Form…• Use same query as last weeks lecture

– Create column form– Move fields– Add header– Insert new sub form– Link

Page 20: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 20

Creating Main Form…

Page 21: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 21

Main Form Totals…• Need to add totals to

main form– Sub Total– VAT– Grand Total

• Add 3 text boxes and labels to footer– Format as desired– Set Names and

Captions as needed

• Sub Total– Already calculated on

Sub Form footer

• VAT– =[SubTotal]*0.175

• Grand Total– =[SubTotal]+VAT]

Page 22: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 22

Main Form Totals…• Sub Total Box

– Set control Source equal to OrderTotal on sub form

Page 23: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 23

Sub Total Expressions…

Page 24: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 24

VAT…

Page 25: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 25

Grand Total…

Page 26: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 26

Final Design…

Page 27: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 27

Final Form…

Page 28: Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To use expressions to perform more complex calculations in.

Mark Dixon Page 28

Tutorial Exercise: Countries• Task 1: Use a form and sub-form to enter

data for Countries and Continents

• Task 2: Create a query that includes calculated fields for population density and population change