S511 Session 9, IU-SLIS 1 DB Implementation: MS Access Macros & Expressions.

Slides:



Advertisements
Similar presentations
Database Design Week 10.
Advertisements

Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Some Introductory Programming 1. Structured Query Language (SQL) - used for queries. - a standard database product. 2. Visual Basic for Applications -
® Microsoft Access 2010 Tutorial 5 Creating Advanced Queries and Enhancing Table Design.
By Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson, Linda Lau, Jerri Williams Chapter 5 Data Validation and Data Analysis.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
VBA Modules, Functions, Variables, and Constants
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Access Tutorial 5 Creating Advanced Queries and Enhancing Table Design
Eyad Alshareef 1 Creating Custom Forms Part A. 2Eyad Alshareef Data Block and Custom Forms Data block form Data block form Based on data blocks that are.
By Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson, Linda Lau, Jerri Williams Chapter 10 Using Macros and SQL in Access 1.
Access Tutorial 3 Maintaining and Querying a Database
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
MS Access Advanced Instructor: Vicki Weidler Assistant:
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
Microsoft Access Intro Class 5 Working with Queries.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith.
 A database is a collection of data that is organized so that its contents can easily be accessed, managed, and updated. What is Database?
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Microsoft Access 2010 Building and Using Queries.
Analyzing Data For Effective Decision Making Chapter 3.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 10 Customizing a Database.
® Microsoft Access 2010 Tutorial 5 Creating Advanced Queries and Enhancing Table Design.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
1 By: Nour Hilal. Microsoft Access is a database software where data is stored in one or more Tables. A Database is a group of related Tables. Access.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Intro to Excel - Session 7.31 Tutorial 7 - Session 7.3 Developing an Excel Application.
S511 Session 7, IU-SLIS 1 DB Implementation: MS Access Forms.
WHAT IS A DATABASE? A DATABASE IS A COLLECTION OF DATA RELATED TO A PARTICULAR TOPIC OR PURPOSE OR TO PUT IT SIMPLY A GENERAL PURPOSE CONTAINER FOR STORING.
Microsoft Access 2013 ®® Tutorial 10 Automating Tasks with Macros.
® Microsoft Access 2010 Tutorial 3 Maintaining and Querying a Database.
COMPREHENSIVE Access Tutorial 3 Maintaining and Querying a Database.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
1 Chapter 3: Customize, Analyze, and Summarize Query Data Exploring Microsoft Office Access 2007.
VB for applications. Lesson Plan Fundamentals of VB VB for handling events in Access.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
® Microsoft Access 2010 Tutorial 5 Creating Advanced Queries and Enhancing Table Design.
Access Queries Agenda 6/16/14 Review Access Project Part 1, answer questions Discuss queries: Turning data stored in a database into information for decision.
1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith Mast, and Mary Anne.
Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications.
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Creating Advanced Queries and Enhancing Table Design.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
DAY 20: ACCESS CHAPTERS 5, 6, 7 Larry Reaves October 28,
Retrieving Data Using the SQL SELECT Statement
DB Implementation: MS Access Macros
Creating LOVs and Editors
Microsoft Access 2003 Illustrated Complete
Microsoft Access Illustrated
DB Implementation: MS Access Forms
Exploring Microsoft Office Access 2007
DB Implementation: MS Access Queries
DB Implementation: MS Access Macros
Restricting and Sorting Data
CIS16 Application Programming with Visual Basic
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
DB Implementation: MS Access Forms
Tutorial 5 Advanced Queries and Enhanced Table Design
Presentation transcript:

S511 Session 9, IU-SLIS 1 DB Implementation: MS Access Macros & Expressions

S511 Session 9, IU-SLIS 2 Outline Expressions in Access Access Macros ► Macro Actions ► Functions ► Creating a Macro MS Access File for Lecture

S511 Session 9, IU-SLIS 3 MS Access Expressions: Intro What is an “expression” in MS Access? ► Combination of functions, operators, constants, & identifiers that evaluates to a single value Identifier  name of field, control, or property (e.g., Forms![Orders]![OrderID]) Operator  arithmetic (+ - * /), comparison (= ), logical (Not And Or), text (& +) ► e.g., =Sum([Purchase Price])*0.08 What does it do? ► Perform calculations ► Manipulate (e.g., combine, extract) text ► Check data values Expression Builder ► MS Access tool to help build expressions ► Can select from the lists of Built-in functions, operators, and constants. Identifiers  Database object (table, query, form, report)  Object elements (fields, controls, properties) MS Access 2007: Expression Builder

S511 Session 9, IU-SLIS 4 Access Expressions: Usage Where to use expressions ► Control Source property in Form or Report = DateAdd("yyyy",10,[Employees]![HireDate]) ► Default property in Form or Report = Date() ► Validation Rule property in Table or Form In ("Mr.","Mrs.","Ms.") ► Criteria in Query Between #1/1/1998# AND #12/31/1998 ► Calculated Field in Query Age: DateDiff(“yyyy”,[BirthDate],Date()) ► SQL Statements in Query or Macro ► Action Arguments and Conditions in Macro ► Arguments for VBA functions, statements, and methods

S511 Session 9, IU-SLIS 5 Access Expressions: Specifying Values Specify values in expressions using ► Contants (i.e, literal values) number, string, or dates; exactly as written  e.g. 10, “Bloomington”, #1/1/1998# Access contants  True, False, Null, “” (empty string) ► Functions Returns values of calculation/operation e.g. Date(), Sum([Sales]) ► Field, Control, Property Identifiers Syntax  ObjectType![ObjectName]![Control/FieldName].PropertyName  e.g. Forms![Orders]![OrderDate].DefaultValue ! operator indicates that what follows is a user-defined item.. operator indicates what follows is an item defined by MS Access. Only need to specify enough parts of an identifier to make it unique MS Access 2007: Expression Syntax

S511 Session 9, IU-SLIS 6 Access Expressions: Functions FunctionDescriptionExample Date()Returns system date Date()  10/16/2007 DatePart(interval, date)Extracts part of a date DatePart(“yyyy”,Date())  2007 DateDiff(interval, date1,date2)Computes difference between two dates DateDiff(“d”,#9/11/2007#,Date())  35 DateAdd(interval, number,date)Returns the date with a time interval added DateAdd(“m”,2,Date())  12/16/2007 Iif(expr, trueval, falseval)Returns a truth value of an expressionIIf([Due Date]<Date(),"OVERDUE", IIf([Due Date]=Date(),"Due","Not Yet Due")) InStr(start, string1, string2)Returns a position of string1 in string2 Instr(1,” “,“Kiduk Yang”)  6 Left(string, length)Returns a substring from the left Left(“Kiduk Yang”, 5)  “Kiduk” Right(string, length)Returns a substring from the right Right(“Kiduk Yang”, 4)  “Yang” Mid(string, start,length)Returns a substring from start Mid(“Kiduk Yang”, 7)  “Yang” Len(string)Returns the number of characters in a string Len(“Kiduk Yang”)  10 Switch(expr1,val1,expr2,val2,..)Returns the value associated w/ first true exprSwitch([City]=“Mexico”,”Spanish”, [City]=“Seoul”, “Korean”) Nz(variant, value)Converts the Null value of a variant to a valueNz([UnitsInStock],0) + Nz(UnitsInOrder,0) DLookup(expr, domain, criteria)Returns the field value of a specific recordDLookup(“[LastName]”,”EMPLOYEE”,”[EmpID]=1”) DSum(expr, domain, criteria)Sum the field values of a specific record setDSum(“[Price]”,”SALES”,”Month([SaleDate])=10”) MS Access 2007: Functions MS Access 2007: Operators

S511 Session 9, IU-SLIS 7 Access Expressions: Examples =IIf(IsNull([Initial]), [FName]&“ ”&[LName], [FName]&“ ”&[Initial]&“ ”&[LName]) ► Display “Firstname Lastname” if no initial, “Firstname Initial Lastname” otherwise =[Sales]/Sum([Sales]) ► Display the proprotion of current sales =DLookup(“[Name]”, “qryEmployees”, “[EmpD]=Forms![frmEmployees][EmpID]”) ► Display Name in qryEmployees, whose EmployeeID matches that entered in the active form =DSum(“[OrderAmount]”, “Orders”, “[CustomerID]=‘Doe’”) ► Display the total order amount of the cutomer “Doe” Year([OrderDate])=Year(Now()) AND Month([OrderDate])=Month(Now()) ► Query Criteria: where order date is in current year and month Areacode: Mid([Phone], 2, 3) ► Query Field: display 3 characters starting with the 2 nd character in [Phone] = Nz([UnitsInStock],0) + Nz(UnitsInOrder,0) ► Form Control Source: show total number of units SELECT ALL from [Employees] WHERE [LastName]=“Doe” ► SQL: return Employees rows with LastName = “Doe”

S511 Session 9, IU-SLIS 8 Programming in MS Access Modules ► An organized collection of Visual Basic for Application (VBA) code ► More flexible and powerful than macros, but less secure Macros ► A named set of actions that perform operations/tasks e.g. open/close a form, print a report, set value of a control ► Tool to automate tasks and extend functionalities without programming Macro actions/functions = subset of commands available in VBA ► Command Button Wizard To perform Common Tasks ► Macro Builder Build a list of actions to perform by selecting from list of actions

S511 Session 9, IU-SLIS 9 Access Macros: Elements Event ► The reason the macro “fires” or runs. i.e., the trigger for a macro execution e.g., a form control gaining/losing focus, mouse click/movement Action ► What the macro does e.g. load/close/delete object, set field/control value Action Arguments (properties) ► What action applies to e.g. frmEmployee Conditions ► Conditions that must be true for the macro to run e.g. IsNull(Forms![frmEmployee]![Status])

S511 Session 9, IU-SLIS 10 Access Macros: Events Event is the reason the macro “fires” or runs. ► A macro’s execution should be triggered by a specific event ► Successful macro use depends on attaching to appropriate events good macro design. ► Example After Update vs. Lost Focus event  loss of focus can occur without data entry or edit  for data entry trigger, use “After Update” event Associating Events and Macros ► Set the appropriate Event Property of the control to the name of the macro that will perform desired actions.

S511 Session 9, IU-SLIS 11 Access Macros: Grouping Simple/Embedded Macro ► A single macro ► Actions are executed sequentially from top to bottom Macro Group ► Related macros grouped together in a macro object ► Individual macros in a macro group are referenced by MacroGroupName.MacroName  e.g. mcrOpenCloseGRP.CloseImOpen