Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
The Web Warrior Guide to Web Design Technologies
Advanced Microsoft Word Hosted by Jared Hoffman Topics Keyboard Shortcuts Customizing Toolbars and Menus Auto Format & Auto Correct Tabs Inserting Pictures.
Chapter 6 Multiform Projects Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
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.
VBA Modules, Functions, Variables, and Constants
Automating Tasks With Macros
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
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.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Using the Visual Basic Editor Visual Basic for Applications 1.
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.
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.
Introduction To Form Builder
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Access Tutorial 10 Automating Tasks with Macros
Chapter 9 Macros, Navigation Forms, PivotTables, and PivotCharts
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Using the Select Case Statement and the MsgBox Function (Unit 8)
Microsoft Visual Basic 2005: Reloaded Second Edition
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.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
XP Chapter 7 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Enhancing User Interaction Through Programming Chapter.
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.
Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
An Introduction to Visual Basic
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
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.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 10 Customizing a Database.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
OCC Network Drives  H:\  P:\ 
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.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter Two Creating a First Project in Visual Basic.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
Access Forms and Queries. Entering Data in Your Table  You can add data to your table in Datasheet view, by typing in the columns and rows.  This.
® Microsoft Access 2010 Tutorial 10 Automating Tasks with Macros.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Macros in Excel Using VBA Time Required – 5 hours.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Chapter 1: An Introduction to Visual Basic 2015
Microsoft Access Illustrated
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
CIS16 Application Development Programming with Visual Basic
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects

2 Copyright © CIST Introduction VBA is an object-oriented programming (OOP) language. OOP is a type of programming in which programmers define a complete data structure from data types to the operations that can be applied to the data structure. The basic building block of OOP is the object. An object is a set of code that represents a thing in our program. A “thing” can be anything: customer, car, house, employee, etc. Objects have two fundamental things that they do: –Store Data –Logic to perform an action

3 Copyright © CIST Course objectives This course will explain you the basic concepts of the object- oriented programming environment, such as using objects in your programs. You will learn the definition of properties, methods, and events, and when to use each one. Because the code is encapsulated into objects with properties, methods, and events available for the objects - a concept called object-oriented programming (OOP)- you can build reusable objects that save a lot of development time. Coding is simplified because the system is organized into smaller sets of interrelated objects, instead of one huge object. Your code will be easier to maintain because it will be easier to understand.

4 Copyright © CIST Elements of an object Definition: Objects are all the things that make up your Access database, such as forms, reports, modules, macros, and tables. Each object has properties that determine its behavior or appearance, as well as methods that determine which actions can be taken upon it. Objects also respond to events that are triggered by actions taken by the user or caused by the system.

5 Copyright © CIST What is a Property? Definition: Properties are characteristics of an object that determine its behavior or appearance. Examples of properties include the name, caption, or size of a control. The property values that are set in the Properties dialog box, such as the Caption property shown previously, are called design time settings. Design time settings are those you specify at design time that become the starting value settings for that object. The starting value can be modified at runtime in your VBA code, or at a later time in design view. For example, to change the Caption property of the preceding form at runtime while the program executes, you could use the following VBA command: Forms.Item("frmTestProperties").Caption = "New caption goes here."

6 Copyright © CIST What is a Method? Definition: Methods are actions that can be taken on an object. They are really sub procedures or functions that are called to perform a particular action. You do not see the code behind sub procedures or functions when using existing Access objects, but they are there. An example of a method you have already used is: Debug.Print Remark: After you make the call to the object, you type a dot (or period). As soon as you do, Auto List Members opens, giving you a list of properties and methods available.

7 Copyright © CIST What is an Event? Definition: Events are triggered by actions taken by the user and the application, such as changes to data, mouse movements, or the opening of a form. You use VBA code or macros to respond to events. In other words, you link up the code you write with the user interface of your application through events. For example, you specify which VBA procedure or function to run when a particular event happens. Microsoft Windows already has the code to handle routine events built right into it. Because VBA and Access are so closely tied to the Windows environment, a lot of routine functions will be handled without your writing a drop of programming code. All you need to do is tell Access what action you want to occur. Once you assign the action, Access writes an event procedure. This is a small block of VBA code that is written for you.

8 Copyright © CIST What is Collection? Definition: A collection comprises multiple objects. Thus, an object can be a member of a collection. Sometimes you may want to manipulate a specific object; For example, a particular form, whereas other times you may want to manipulate a collection of objects (all the forms in your database).

9 Copyright © CIST Elements of an object–Exercise 1 It’s your turn now to try your hand at an example that uses properties, methods, and events. As you work, try to keep track of which items are properties, which are methods, and which are events. 1. Create a new database and specify the file name as ObjectExamples. You can close the empty table that opens by default, as you will not be using a table in this example. 2. Add a new form to the database and then select the Design View. 3. On the new form, use the ToolBox to select and draw a text box control and a command button on the form. You can select Cancel to the wizard dialog boxes that appear.

10 Copyright © CIST Elements of an object–Exercise 1 4. Select the text box control and from the Properties dialog box, select the All tab, and change the Name property to txtDateOfBirth. 5. Select the label. From the Properties dialog box, change the Name property of the label to lblDateOfBirth. Change the Caption property of the label to Enter Date of Birth. 6. You may need to resize the label to display all its contents. 7. Select the Command button. From the Properties dialog box, change the Name property of the Command button to cmdCalculate, and change the Caption property to Calculate. The form should now look like this:

11 Copyright © CIST Elements of an object–Exercise 1 Close the form to save it, and when prompted, specify the name frmTestObjects for the form. Reopen the form by selecting it in the Navigation Pane, and switch back to design view. Select the txtDateOfBirth text box again. Select the Event tab of the Properties dialog box, and locate the On Exit event. Select the Code Builder option to open VBE to write code for the event. One way to do so is to choose Event Procedure in the drop-down list and then click the ellipsis (…). You can also select the Ellipsis button and then choose Code Builder from the dialog box that appears. Add the following code to the Exit event: Private Sub txtDateOfBirth_Exit(Cancel As Integer) 'if the user did not enter a date, then 'display an error and set the focus back 'to the date of birth text box control. If Not IsDate(txtDateOfBirth.Text) Then MsgBox "You must enter a date for the Date of Birth field." txtDateOfBirth.SetFocus Cancel = True End If End Sub

12 Copyright © CIST Elements of an object–Exercise 1 Select the cmdCalculate command button. On the Event tab of the Properties dialog box, select the On Click event, then click the ellipsis, then Code Builder, and add the following code to the newly created event procedure as shown here: Private Sub cmdCalculate_Click() 'declare local variable for month of birth Dim intMonthOfBirth As Integer 'convert the value in the text box to a 'month and assign the value to the month of birth variable intMonthOfBirth = DatePart("M", CDate(txtDateOfBirth)) 'display a message to the user regarding the month of birth MsgBox "Month you were born: " & intMonthOfBirth End Sub Click the Save button from the toolbar to save all the changes. Return to the frmTestObjects form in Access and click the Save button to save all changes on the form. Run the form by clicking the Home ribbon and clicking the Form View item on the View list.

13 Copyright © CIST Elements of an object–Exercise 1 Enter something in the text box other than a date: Now, click the Calculate button. The message should be similar to the one shown After you click the OK button, focus returns to the Date of Birth text box field. Type your date of birth: Click the Calculate button. You should get a message box giving your month of birth.

14 Copyright © CIST Viewing Objects Using the Object Browser Now that you understand what objects and their respective properties, methods, and events are, let’s look at another way to view objects. The Object Browser is a tool that allows you to view and manage the objects in your application. You can use the Object Browser to learn about the objects available in Access The Object Browser can be opened from the Visual Basic Editor in one of three ways: –by choosing the Object Browser button on toolbar, –by selecting View Object Browser, –or by pressing F2.

15 Copyright © CIST Ways to Refer to Objects You should also know the various ways to refer to an object. Here are some examples: Forms.frmTestObjects Forms!frmTestObjects Forms("frmTestObjects") Forms(0) Using the period (Forms.frmTestObjects) is the preference for most situations because you can see the list of available properties, methods, events, and constants as you type. You can also refer to objects using the Me keyword as a shortcut. Me refers to the current object. So if you use Me in a form module, it refers to the form. Here is an example: Me.txtDateOfBirth An equivalent, but longer, version of the same statement is: Forms.frmTestObjects.txtDateOfBirth Only use the Me keyword when you want to refer to the existing object (not to a totally different object).

16 Copyright © CIST Any Question?

17 Copyright © CIST The End