Form’s Events ISYS 562. Form Events Opening & closing form:Open, Close, Load, Unload Moving to and from the form: Activate, deactivate Moving from control.

Slides:



Advertisements
Similar presentations
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Advertisements

CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
Using Macros and Visual Basic for Applications (VBA) with Excel
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
Customizing Reports. Custom Reports A report is a formatted hardcopy of the contents of one or more tables from a database. Although you can format and.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA By Robert T. Grauer Maryann Barber.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Customizing Word Microsoft Office Word 2007 Illustrated Complete.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Event-Driven Programming and Access Events
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab2 Managing Controls.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Introduction To Form Builder
Access Macros ISYS 562. Why Use Macro? In Microsoft Access, you can accomplish many tasks by using macros. Macros are an easy way to take care of simple.
MsgBox Function Displays one of Visual Basic’s predefined dialog boxes, which contains a message, one or more command buttons, and an icon After displaying.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Business Computer Information Systems Microsoft Office XP Access Review Lessons 1 through 5.
© 2001 ComputerPREP, Inc. All rights reserved. Access 2000: Introduction to Application Development.
Access Tutorial 10 Automating Tasks with Macros
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Chapter 3 Maintaining a Database
Tutorial 6 Using Form Tools and Creating Custom Forms
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
Lab 9 – User Forms Design. User Forms What are user forms? –Known as dialog boxes –Major ways for getting user input An example of using user forms: Monthly.
VBA – Visual Basic for Applications Week 20 - Tutorial.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Using Visual Basic for Applications (VBA) – Project 8.
Chapter 4: The Selection Process in Visual Basic.
CHƯƠNG 3 Finding, Filtering, and Formatting Data.
S511 Session 7, IU-SLIS 1 DB Implementation: MS Access Forms.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Database Systems Microsoft Access Practical #1 Creating Tables Nos 215.
Key Applications Module Lesson 21 — Access Essentials
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Databases,Tables and Forms Access Text by Grauer Chapters 1 & 2.
DB Implementation: MS Access Forms. MS Access Forms  Purpose Data entry, editing, & viewing data in tables Forms are user-friendlier to end-users than.
1 MIS309 Database Systems Introduction to Microsoft Access.
McGraw-Hill Technology Education © 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Office Access 2003 Lab 2 Modifying a Table and Creating.
Microsoft Access 2002 Illustrated Complete Forms Using.
Introduction to a Database Defining a database Database window in Access The six items in window: Tables, Queries Forms, Reports, Macros, Modules.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
More Form Tools Combo Box (displays a list) Check Box (yes/no) Frame (groups option buttons) Option Button (exclusive choice) Ref Edit (user selects cells)
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
VB Objects & Events (Exercises) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Friday 1/31/2003)
1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith Mast, and Mary Anne.
MIS333k(Poynor) Chapter 2. Intro to VBA Events Where to plug in your programs?
Microsoft Access 2000 Modifying Tables, Creating Forms and Viewing Data.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Microsoft Access Prepared by the Academic Faculty Members of IT.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
CIS 338: Events Dr. Ralph D. Westfall April, 2011.
Implement User Input Windows Development Fundamentals LESSON 2.4A.
1 Chapter 6: Creating Oracle Data Block Forms. 2 Forms  Application with a graphical user interface that looks like a paper form  Used to insert, update,
Introducing UserForms Joanna Wyrobek 1. Ms Excel UserForms A UserForm object is a window or dialog box that makes up part of an application's user interface.
DB Implementation: MS Access Forms. MS Access Forms: Purpose Data entry, editing, & viewing data in Tables Forms are user-friendlier to end-users than.
User Forms.
DB Implementation: MS Access Forms
Custom dialog boxes Unit objectives
DB Implementation: MS Access Forms
Presentation transcript:

Form’s Events ISYS 562

Form Events Opening & closing form:Open, Close, Load, Unload Moving to and from the form: Activate, deactivate Moving from control to control: Enter, Exit, Getfocus, Lostfocus Pressing keys: KeyDown, KeyUp, KeyPress Clicking mouse: Click, DblCLick, MouseUp, MouseWheel Changing data: dirty, BeforeUpdate, AfterUpdate, Undo Adding records: BeforeInsert, AfterInsert Deleting records: Delete, BeforeDelConfirm, AfterDelConfirm Filtering records: Filter, ApplyFilter

Order of events for controls on forms

Moving the focus to a control When you move the focus to a control on a form— for example, by opening a form that has one or more active controls or by moving to another control on the same form— the Enter and GotFocus events occur in this order:Enter → GotFocus If you are opening a form, these events occur after the events associated with opening the form (such as Open, Activate, and Current), as follows: –Open (form) → Activate (form) → Current (form) → Enter (control) → GotFocus (control) When the focus leaves a control on a form— for example, when you close a form that has one or more active controls or move to another control on the same form— the Exit and LostFocus events occur in this order:Exit → LostFocus If you are closing a form, the Exit and LostFocus events occur before the events associated with closing the form (such as Unload, Deactivate, and Close), as follows: –Exit (control) → LostFocus (control) → Unload (form) → Deactivate (form) → Close (form)

Changing and updating data in a control When you enter or change data in a control on a form and then move the focus to another control, the BeforeUpdate and AfterUpdate events occur: –BeforeUpdate → AfterUpdate The Exit and LostFocus events for the changed control occur after the BeforeUpdate and AfterUpdate events: –BeforeUpdate → AfterUpdate → Exit → LostFocus When you change the text in a text box or in the text box portion of a combo box, the Change event occurs. This event occurs whenever the contents of the control change, but before you move to a different control or record (and thus, before the BeforeUpdate and AfterUpdate events occur). The following sequence of events occurs for each key you press in a text box or in the text box portion of a combo box: –KeyDown → KeyPress → Dirty → Change → KeyUp The NotInList event occurs after you enter a value in a combo box that isn't in the combo box list and then attempt to move to another control or record. It occurs after the keyboard events and the Change events for the combo box, but before any other control or form events. If the LimitToList property of the combo box is set to Yes, the Error event for the form occurs immediately after the NotInList event: KeyDown → KeyPress → Dirty → Change → KeyUp → NotInList → Error

Order of events for records on forms Events occur for records on forms when you move the focus to a record, update data in a record, delete an existing record or records, or create a new record.

Moving the focus to records and updating data in records When you move the focus to an existing record on a form, enter or change data in the record, and then move the focus to another record, the following sequence of events occurs for the form: –Current (form) → BeforeUpdate (form) → AfterUpdate (form) → Current (form) When you leave the record whose data has changed, but before you enter the next record, the Exit and LostFocus events occur for the control with the focus. These events occur after the BeforeUpdate and AfterUpdate events for the form, as follows: BeforeUpdate (form) → AfterUpdate (form) → Exit (control) → LostFocus (control) → RecordExit (form) → Current (form) As you move the focus among the controls on a form, events occur for each control. For example, the following sequences of events occur when you: Open a form and change data in a control: Current (form) → Enter (control) → GotFocus (control) → BeforeUpdate (control) → AfterUpdate (control) Move the focus to another control: Exit (control1) → LostFocus (control1) → Enter (control2) → GotFocus (control2) Move the focus to another record: BeforeUpdate (form) → AfterUpdate (form) → Exit (control2) → LostFocus (control2) → RecordExit (form) → Current (form)

Changing and updating data in a control When you enter or change data in a control on a form and then move the focus to another control, the BeforeUpdate and AfterUpdate events occur. The Exit and LostFocus events for the changed control occur after the BeforeUpdate and AfterUpdate events: –BeforeUpdate → AfterUpdate → Exit → LostFocus

Deleting records When you delete a record, the following events occur for the form, and Microsoft Access displays a dialog box asking you to confirm the deletion: –Delete → BeforeDelConfirm → AfterDelConfirm If you cancel the Delete event, the BeforeDelConfirm and AfterDelConfirm events don't occur and the dialog box isn't displayed.

Creating a new record When you move the focus to a new (blank) record on a form and then create a new record by typing in a control, the following sequence of events occurs: –Current (form) → Enter (control) → GotFocus (control) → BeforeInsert (form) → AfterInsert (form) The BeforeUpdate and AfterUpdate events for the controls on the form and for the new record occur after the BeforeInsert event and before the AfterInsert event.

Keyboard events When you press and release a key while a control on a form has the focus (or use the SendKeys action to send a keystroke), the following sequence of events occurs: –KeyDown → KeyPress → KeyUp

Mouse Events When you press and release a mouse button while the mouse pointer is on a control on a form, the following sequence of events occurs for the control: –MouseDown → MouseUp → Click If a control has the focus and you click another control to move the focus to this second control, the following sequences of events occur: –First control: Exit → LostFocus –Second control: Enter → GotFocus → MouseDown → MouseUp → Click

VB Modules Standard modules: –Standard modules are separated database objects containing one or many procedures. They most often contains utilities functions that are useful in many different circumstances. –Create a standard module: In the database window, click Modules and New. Form/Report modules: Containing procedures belong to a form/report –Create a form module: In the Form Design view, click the Code button

VB Editor

Event Procedure Create an event procedure: –Select control –Select control’s event Event procedure’s argument: Private Sub CITY_BeforeUpdate(Cancel As Integer) End Sub Private Sub CITY_KeyDown(KeyCode As Integer, Shift As Integer) End Sub Private Sub Command10_Click() End Sub

Keep ComboBox (listBox) Synchronized with the Form Use Form’s OnCurrent event: –Example: A form to display employee table with a comboBox of empID: ComboBoxName = EmpID

Filtering Form Data Filter By Selection button (Form View Toolbar or Format Toolbar) –Example: While viewing employee record, click Race field, and click Filter By Selection button. –Click the Remove Filter to remove the filter. Filter By Form button: –Click the button –Click the field and select a value (may select many fields) Advanced Filter/Sort : –Format toolbar: Record/Filter –QBE window

Form’s Filter Event Triggered when a user chooses the Filter By Form or Advanced Filter/Sort command.

Form’s Filtering Properties Form’s Filter property: –Me.Filter = “sex = ‘male’” Form’s FilterOn property –True if we apply the filter

Using Filter Properties Private Sub Command16_Click() Me.Filter = "race='" & Race & "'" Me.FilterOn = True End Sub Private Sub Command17_Click() Me.FilterOn = False End Sub

Automatically Fill an Unbound Textbox with a Calculated Result Example: –Employee pays $50 for an event if salary<50000 –Otherwise, $100. Private Sub Form_Current() List14 = EmpID If Salary <= Then Text24 = 50 Else Text24 = 100 End If End Sub

Label Format –Caption, Visible Data –SmartTag Event Other –Name –ControlTip text

TextBox Format –Format, Visible Data –Control source –Inputmask –Validation rule –Default value –Smart tags Event –OnDirty, BeforeUpdate, AfterUpdate

Creating a Bound Form Using Design View Form: Record source Textbox: –Control source –Format –Inputmask Buttons: Move Next, Move Previous

SmartTag with a TextBox Name address

Using Textbox’s Events After entering annual income in an unbound box, Use the BeforeUpdate to check input, then use the AfterUpdate event to display event ticket fee based on the following rules: –If income <= then Fee = 100 –Else Fee = 200 Private Sub Text6_AfterUpdate() If Text6 <= Then Text8 = 100 Else Text8 = 200 End If End Sub Private Sub Text6_BeforeUpdate(Cancel As Integer) If Text6 <= Then MsgBox ("Must be greater than 10000") Cancel = True End If End Sub

Required Field Use textbox’s validation rule: –Not Null Use textbox’s BeforeUpdate event: –If isNull(text2) then Msgbox(“Must enter a value”) Cancel=true –End if

Responding to Keyboard Events Events: –KeyPress: Normal characters –Letters, numbers –KeyDown, KeyUp: Handle the exact keys that are being pressed including combinations that use special keys such as Shift, Alt, Ctrl

VBA Constants In VB Editor view: –View/Object Browser –Choose VBA Type constant to search –Color Constants –Key Code constants

KeyDown Event Arguments Textbox: City –Private Sub CITY_KeyDown(KeyCode As Integer, Shift As Integer) –KeyCode: –Shift: = 1 if Shift key is pressed = 2 if Control key is pressed = 3 if Alt key is pressed

Example of Using KeyDown Event to Enter Data Private Sub CITY_KeyDown(KeyCode As Integer, Shift As Integer) If Shift = 2 Then If KeyCode = vbKey1 Then CITY = "san francisco" RATING = "A" ElseIf KeyCode = vbKey2 Then CITY = "los angeles" RATING = "A" End If End Sub

Option Group Option Group wizard Testing Option Group selection: –If Frame18 = 1 Then Me.Filter = "sex='male'" Else Me.Filter = "sex='female'" –End If

Private Sub Frame18_AfterUpdate() If Frame18 = 1 Then Me.Filter = "sex='male'" Else Me.Filter = "sex='female'" End If Me.FilterOn = True End Sub

CheckBox If checked, the checkbox has a value of -1 If unckecked, it has a value of 0. If Check17 = -1 Then MsgBox ("You check check17") Else MsgBox ("You uncheck chk17") End If

Option Box (Radio Button) If Option19 = -1 Then MsgBox ("You check OptionBox") Else MsgBox ("You uncheck OptionBox") End If

ListBox Format: –Column count Data: –Control source –Row source type –Row source Listbox’s value: –MsgBox (List23)

Access Macros ISYS 562

Macro’s Actions OpenForm, OpenReport TransferDatabase, TransferSpreadsheet OutputTo CopyDatabaseFile, CopyObject FindNext, FindRecord RunCode, RunCommand, RunSQL, RunApp, RunMacro SendObject SetValue

Macro Condition You can use any expression that evaluates to True/False or Yes/No in a macro condition. The macro will be executed if the condition evaluates to True. To add a condition: –At macro design view: View/Condition

Convert Macro to VB Tools/Macro/Convert macros to VB Each action is converted to an Access DoCmd command. To view DoCmd command: –Object Browser –Choose Access –Search DoCmd