VB for applications. Lesson Plan Fundamentals of VB VB for handling events in Access.

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
ERWin Template Overview By: Dave Wentzel. Agenda u Overview of Templates/Macros u Template editor u Available templates u Independent column browser u.
VBA Modules, Functions, Variables, and Constants
Systems Development Group Project Programming Access Forms.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Designing a Database Unleashing the Power of Relational Database Design.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Microsoft © Access 2000 Types of Forms Forms & Real Estate Conclusion Questions Why use a Form What is a Form Data behind a Form Controls on a Form Code.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Private Sub Close_Click() On Error GoTo Err_Close_Click DoCmd.Close Exit_Close_Click: Exit Sub Err_Close_Click: MsgBox Err.Description Resume Exit_Close_Click.
Using the Select Case Statement and the MsgBox Function (Unit 8)
Review. Focused concept Week 1: Three separate types of functionality: Data Management Application logic Presentation Single-tier, client-server, three-tier.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Form and Graphical User Interfaces. Lesson plan More about queries More about entering data into a table Form.
Using Visual Basic for Applications (VBA) – Project 8.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
S511 Session 9, IU-SLIS 1 DB Implementation: MS Access Macros & Expressions.
1 All Powder Board and Ski Microsoft Access Workbook Chapter 7: Integrity and Transactions Jerry Post Copyright © 2003.
You can use Access forms to create an interface to your reports and queries. You can add: Buttons to initiate reports and queries Combo Boxes, List.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
Applications Development
1 MIS309 Database Systems Introduction to Microsoft Access.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
Unbound Form Form not tied directly to any fields in the database Must use SQL to “bind” the fields 1.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
CS130 Visual Basic Project 4 Lecture Fall New topics in project 4 Database, file (table), records, fields. Application that contains menus, submenus,
Understanding Visual Basic Fundamentals CHAPTER 13 Understanding Visual Basic Fundamentals.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Chapter 3: Relational Databases
Using a Database Access97 Please use speaker notes for additional information!
Mark Dixon 1 Soft051 Examination Sample Questions.
Form and Graphical User Interfaces. Lesson plan More about queries More about entering data into a table Form.
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Microsoft Access Illustrated
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Database systems Lecture 3 – SQL + CRUD
Contents Preface I Introduction Lesson Objectives I-2
Presentation transcript:

VB for applications

Lesson Plan Fundamentals of VB VB for handling events in Access

Project 1 (parts 1-2-3) Avg = (27 submissions)

Visual Basic in Access Previous version (< 2002) –Use macro to perform automation –Use VB This version - Very little support for macro (only for backward compatibility) - Focus on VB

Visual Basic in Access VB is a real programming language and is NOT a macro language We focus on using VB for handling user-initiated events (keyboard press, mouse lick..) Where do we use Visual Basic for Applications code? –Docmd command –Write query expression –To create user-defined functions –Even handling, error handling …

Modules Form modules: –Contain code in response to event- triggered by a user using controls of a form Report modules –Contain code in response t event-trigged by reports, sections of reports Access modules, and Class modules –Allows you to define custom objects

Modules One or more procedures (sub-procedures) Example: Private Sub Add_Click() On Error GoTo Err_Add_Click ‘Start procedure code DoCmd.GoToRecord,, acNewRec Exit_Add_Click: ……. ‘End procedure code End Sub

Procedures Definition: private/public SUB ‘ code right here end SUB Similar to void-returned method in Java/C++ (or void returned functions in C)

Functions Functions: private/public FUNCTION ([Parameter as Datatype]) As ReturnType ‘ code right here end Function Similar to non-void-returned method in Java/C++ (or non- void returned functions in C)

Datatype Symbol value: type-declaration character Byte: [0,255] Symbol value: none Integer: [-2 31, ] Symbol value: % Boolean: true, false. Symbol value: none Long: [-2,147,483,648; 2,147,483,647] Symbol value: & Double: Symbol value: # Currency: symbol String: symbol value $ Date: symbol value none

Variables and naming conventions Implicit variables: IntegerVar% = 1234 Explicit variables: Dim IntegerVar As Integer

Variables Arrays: are variables that consists of a collection of values Dim newArray(20) as String ‘create an array with 21 elements indexed from 0 to 20 Dim newArray(1 to 20) as String ‘create an array with 20 elements indexed from 1 to 20

Controlling program flow Conditional statements: If boolean_expression1 then statement to be executed if boolean_expression1 is true Else statement to be executed if boolean_expression1 is false Endif

Controlling program flow Select case statement: Select Case case exp1 statement being executed if the value of variable name = exp1 case exp2 statement being executed if the value of variable name = exp2 …case else: statement being executed if none of the above is met End Select

Controlling program flow Case expression can be: single value or list of values range of values expression with relational operators Example: select case inputStr case “A” to “Z” char = “Upper Case” case “a” to “z” char =“Lower Case”

Repetitive commands For, Next For counter=startValue to stopValue Step stepValue ‘Code are here Next Example: Sum%=0 For i = 1 to 100 step 2 Sum%= Sum%+ i next i

Repetitive commands On Error GoTO Label GoTo label: creates a loop but breaks the structure of a program

VBA for event handling in Access Form -An event: mouse click, mouse movement, keyboard press -VBA code is used to process the actions associated with such an event. -Event procedure from properties for any controls in a form

Adding a button to open a new form

Private Sub Login_Click() On Error GoTo Err_OpenNewUserForm_Click Dim formName As String Dim formCriteria As String formName = "NewUser" DoCmd.OpenForm formName,,, formCriteria Exit_Err_OpenNewUserForm_Click: Exit Sub Err_OpenNewUserForm_Click: MsgBox Err.Description Resume Exit_Err_OpenNewUserForm_Click End Sub

Adding a button to display a specific record on another form

Private Sub DisplayUserInfo_Click() On Error GoTo Err_DisplayUserInfo_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "UserInformation" stLinkCriteria = "[FirstName]=" & "'" & Me![userfirstname] & "'" DoCmd.OpenForm stDocName,,, stLinkCriteria Exit_DisplayUserInfo_Click: Exit Sub Err_DisplayUserInfo_Click: MsgBox Err.Description Resume Exit_DisplayUserInfo_Click End Sub

Adding a button to display a specific record on another form

Private Sub DisplayUserInfo_Click() On Error GoTo Err_DisplayUserInfo_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "UserInformation" stLinkCriteria = "[FirstName] LIKE " & "'" & Me![userfirstname] & "'" DoCmd.OpenForm stDocName,,, stLinkCriteria Exit_DisplayUserInfo_Click: Exit Sub Err_DisplayUserInfo_Click: MsgBox Err.Description Resume Exit_DisplayUserInfo_Click End Sub

Referring to Access Object with VBA Form and form property: Example: Forms!UserInformation Forms!UserInformation.RecordSource Me.RecordSource Me.Userpassword

Validating data

Private Sub ISBN_BeforeUpdate(Cancel As Integer) If IsNull(Me!ISBN) Then MsgBox "This should not be empty" Exit Sub End If firstChar$ = Left(Me!ISBN, 1) Select Case firstChar$ Case 0 To 9 Exit Sub Case Else MsgBox “ISBN should start with a number" Cancel = True End Select End Sub

Practice Work on project 1 – part 5-6

Review for Exam Week 1: Three separate types of functionality: –Data Management –Application logic –Presentation Single-tier, client-server, three-tier architecture How Do Databases Support the World Wide Web

Review for Exam Week 2 Relational model: table, key(PR,FK), row, column, domain,tuple/record, NULL value Data integrity, entity integrity, Referential Integrity, enterprise integrity Views, relationship (three types, how to model them)

Review for Exam Week 3 Normalization Validating data (field level, table level) SQL statements

Review for midterm exam Week 4: Query: boolean expressions, different types of queries (select,action, parameter, crosstab) Different types of joins (equ(inner)joins, left/right joins)

Review for midterm exam Week 5 and week 6: Form and report

Review for midterm exam 1.Matching A-3 B-6 C-4 D-2 E-5 F-1

Review for midterm exam 2.Query operations on a database are very important. Which operation is not a query operation? a. Insert b. Update c. Select d. Model

Review for midterm exam 3. Consider a database with a logical description Employee (employeeNumber, lastName, firstName, age). Select the entry that would most likely be require to be unique a. employeeNumber b. lastName c. firstName d. Age e. None of the above

Review for midterm exam 4. Insert into video (videoId, movieName,typeDVDVHS) values (102, ‘Citizen Kane’,’VHS’); Insert into video (videoId, movieName,typeDVDVHS) values(103, ‘Chicago’,’DVD’);

Review for midterm exam 5. Employee table: Empid: Primary key (PK) State: Foreign key (FK) State table: Stateid: primary key(PK) Relationship between state and employee: one to many State: parent table Employee: child table

Review for midterm exam 5.2. SELECT Employee.Empid, Employee.Salary,Employee.Startdate, State.abbr FROM State INNER JOIN Employee ON State.Stateid=Employee.State WHERE State.abbr='WI';

Review for midterm exam 5.2. SELECT Employee.Empid, Employee.Salary, State.abbr FROM State INNER JOIN Employee ON State.Stateid=Employee.State WHERE Employee.StartDate < #1/1/2004#;

Review for midterm exam 5.4. SELECT STATE, COUNT(EMPID) as TotalEmployee, SUM(SALARY) as TotalSalary FROM EMPLOYEE GROUP BY STATE STATETotalEmployeeTotalSalary

Review for midterm exam Result EMPIDSALARYABBR CT CT NY NY NV WI SELECT EMPLOYEE.EMPID, EMPLOYEE.SALARY, STATE.ABBR FROM EMPLOYEE, STATE WHERE EMPLOYEE.STATE = STATE.STATEID

Review for midterm exam Result EMPIDABBR 00002CT 00005CT 00001NY 00003NY 00004NV 00006WI MD SELECT EMPLOYEE.EMPID, STATE.ABBR FROM STATE LEFT JOIN EMPLOYEE ON EMPLOYEE.STATE = STATE.STATEID

Review for midterm exam Result TotalSalary SELECT SUM(SALARY) FROM EMPLOYEE WHERE STARTDATE > #1/1/2004#

Review for midterm exam Result SALARYSTARTDATE /8/ /20/2003 SELECT SALARY, STARTDATE FROM EMPLOYEE WHERE STATE = (SELECT STATEID FROM STATE WHERE ABBR=”CT”)