Mark Dixon Page 1 06 – Expression Builder. Mark Dixon Page 2 Session Aims & Objectives Aims –To...
-
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...
Mark Dixon Page 1
06 – Expression Builder
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
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]
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
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.
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
Mark Dixon Page 7
Expression Builder…
Expression
Basic Operators
Objects
Fields/Groups
Values/Operators
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)
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
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
Mark Dixon Page 11
An Example…• Customer Order Form
– Similar to the Order details form from last lecture
– Views cost of order as well
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
Mark Dixon Page 13
New Sub Form Query…
• Main form query same as last weeks lecture
Mark Dixon Page 14
New Sub Form…
• Need to add line price– Extend form (left)– Add new Text Box (Details) and Label (Header)
Mark Dixon Page 15
Calculating Totals…
• Text box is Unbound– Open Properties– Set Name– Select Control Source– Click …
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
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])
Mark Dixon Page 18
Final Sub Form…
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
Mark Dixon Page 20
Creating Main Form…
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]
Mark Dixon Page 22
Main Form Totals…• Sub Total Box
– Set control Source equal to OrderTotal on sub form
Mark Dixon Page 23
Sub Total Expressions…
Mark Dixon Page 24
VAT…
Mark Dixon Page 25
Grand Total…
Mark Dixon Page 26
Final Design…
Mark Dixon Page 27
Final Form…
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