University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.

Slides:



Advertisements
Similar presentations
CE 311 K Introduction to Computer Methods VB Controls and Events Daene C. McKinney.
Advertisements

Working with Intrinsic Controls and ActiveX Controls
Driving Test 1 Marking Scheme Focus on five areas to pass driving test 1.
An Introduction to Visual Basic Terms & Concepts.
VISUAL BASIC Visual Basic is derived from the Basic language (Beginner’s All-Purpose Symbolic Instruction Code) Visual Basic uses an event-driven programming.
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
1 Microsoft Access 2002 Tutorial 9 – Automating Tasks With Macros.
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
Automating Tasks With Macros
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
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.
Chapter 1 Program Design
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Chapter 3 Planning Your Solution
Adding Automated Functionality to Office Applications.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
Microsoft Visual Basic 2005: Reloaded Second Edition
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Chapter 4: The Selection Structure
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
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
® 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.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 11 Committed to Shaping the Next Generation of IT Experts. Chapter 10 Customizing a Database.
Chapter 12: How Long Can This Go On?
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Outline Software and Programming Program Structure Tools for Designing Software Programming Languages Introduction to Visual Basic (VBA)
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
University of Sunderland COM 220 Lecture Six Slide 1 Building Interactive Forms Applications using Oracle.
Fundamentals of GUI Programming. Objectives: At the end of the session, you should be able to: describe the guidelines that are used for creating user-friendly.
Introduction to Programming with RAPTOR
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
University of Sunderland CIF 104 Fundamentals of DatabasesUnit 16 SESSION 16 VBA example.
Introduction to Programming G50PRO University of Nottingham Unit 2 : Introduction To Scratch Paul Tennent
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Controlling Program Flow with Decision Structures.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Chapter 1: Introduction to Computers and Programming.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Chapter Topics 15.1 Graphical User Interfaces
Chapter 4: The Selection Structure
An Introduction to Computers and Visual Basic
An Introduction to Visual Basic
Exploring Microsoft Office Access 2007
VISUAL BASIC.
Microsoft Visual Basic 2005 BASICS
Exploring Microsoft Excel
An Introduction to Computers and Visual Basic
Chapter 15: GUI Applications & Event-Driven Programming
Introduction to Programming
Tutorial 10: Programming with javascript
Presentation transcript:

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Introduction Writing Visual Basic for Applications (VBA) code helps to automate your database and makes your database more powerful. The following notes assume that you have a basic knowledge (gained from the three open learning Access books) of creating simple databases with related tables, queries and forms.

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Outcomes At the end of this session you will understand: The role of objects in the Access GUI Event-driven programming Introductory programming concepts How to use VBA to add functionality to a form

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Objects Physical control objects, like textboxes and command buttons are physical entities that have properties and events associated with them. In VBA programming you have to ensure that the focus of the programming sequence is on the object you wish to manipulate. The SetFocus function does this and is assigned to the object (in this case a textbox) in the following way: TextBox1.SetFocus

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Event-driven programming Unlike procedural programming languages where the code is read and executed from top to bottom, apart from loops and other constructs, Access VBA is an event-driven language. This means that the events are executed when the user interacts with the Graphical User Interface (GUI) For example, a message appears when the user clicks on a button

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Introduction to Programming Programming allows you to: –Issue commands to make the system do something –Control how and when these commands are issued In general, each line in a program consists of a single command or control

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming concepts: Variables A variable holds a value in memory for temporary storage for the time that the block of code is being executed. For example you could assign a variable with the name Surname, data type: String This stores the value of a surname that can be input into a text box for example. The physical object that is used to manipulate the variable in this case is the textbox.

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Objects Physical control objects, like textboxes and command buttons are physical entities that have properties and events associated with them. In VBA programming you have to ensure that the focus of the programming sequence is on the object you wish to manipulate. The SetFocus function does this and is assigned to the object (in this case a textbox) in the following way: TextBox1.SetFocus

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Declaring variables Any variables created in VBA programming must be declared as follows: Dim Surname as String Dim Num as Single Dim BirthDate as Date Variable Data type

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 VBA statements and procedures When you combine constants, variables, objects, operator symbols, properties and methods in a single operation, for a set purpose, you produce a statement. When you VBA programme in VBA, you put together the statements in a particular order, following specific syntax rules, into a procedure.

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Function procedure Function procedure –A function procedure is a particular form of procedure that performs a task that may return a value. This returned value is computed in the procedure and assigned to the function name as one of the procedure’s statements. There are several useful in-built functions such as MsgBox function, InputBox function

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Variables to store data Variables to store data When you want to write a procedure or function you will need to declare any variables to hold temporary data. For example if you want to write a procedure to multiply 2 numbers that will be input by the user then you will first need to put two input boxes on a form, a command button to trigger the event and a text box for display.

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Control structures VBA executes a procedure’s statements in sequence beginning with the first statement. It reads the code left to right and then top to bottom-this is called sequential flow. Control constructs influence the execution of a program so that if you want one set of statements to be executed rather than another i.e you want to change the order then you can use constructs to do this. You can use decision structures to test conditions and then perform a particular statement or set of statements depending on the outcome. Or you can use loop structures to execute a set of structures repetitively.

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Making decisions If ……..then The words in italics are the condition, words in bold are the construct commands, words in normal text are the statement If you are feeling too hot then Take some of your clothes off End if (The above algorithm is a form of pseudocode-like a recipe to do something in plain English and not in a programming language

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming an activity

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Simple interaction with the user Open a new form and put a command button on the form and name it cmdAnswer, a label with the caption “The best football team!”, and a textbox called txtTeam with the label “Which is the best team?”. In design view open the code dialog box and type the following in the section for the object cmdAnswer and event

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Writing the code Note the object box And this is the event box So when the button is pressed (object button triggers click event) the code is executed and a message box appears.

University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Summary Access is an even-driven programme When you interact with the interface objects, events happen You can add programming constructs using VBA The tutorial is Exercise 10. The tutorial covers sessions 15 and 16.