0% found this document useful (0 votes)
34 views23 pages

Access 11

This document provides an overview of using and writing Visual Basic for Applications (VBA) code in Access. It covers topics such as functions, subroutines, modules, events, procedures, compiling code, and hiding/changing the color of controls. The objectives are to learn about functions, subroutines, modules, create and modify procedures, and test VBA code. It provides examples of creating functions, subroutines, event procedures, standard modules, and testing and compiling code.

Uploaded by

elhadrami anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views23 pages

Access 11

This document provides an overview of using and writing Visual Basic for Applications (VBA) code in Access. It covers topics such as functions, subroutines, modules, events, procedures, compiling code, and hiding/changing the color of controls. The objectives are to learn about functions, subroutines, modules, create and modify procedures, and test VBA code. It provides examples of creating functions, subroutines, event procedures, standard modules, and testing and compiling code.

Uploaded by

elhadrami anas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Access Tutorial 11

Using and Writing


Visual Basic for
Applications Code

COMPREHENSIVE
Objectives XP

• Learn about Function procedures (functions), Sub


procedures (subroutines), and modules
• Review and modify an existing subroutine in an event
procedure
• Create a function in a standard module
• Create event procedures
• Compile and test functions, subroutines, and event
procedures
• Hide text and change display colors
• Create event procedures for a dialog box

New Perspectives on Microsoft Office Access 2007 2


Introduction to Visual Basic for XP
Applications
• Visual Basic for Applications (VBA) is the
programming language provided with Access and
other Office programs
• VBA has a common syntax and a set of common
features for all Microsoft Office programs
– Event-driven language
– Object-oriented language

New Perspectives on Microsoft Office Access 2007 3


Events XP

New Perspectives on Microsoft Office Access 2007 4


Procedures XP

• A Function procedure, or function, performs


operations, returns a value, accepts input values,
and can be used in expressions (recall that an
expression is a calculation resulting in a single
value)
• A Sub procedure, or subroutine, performs
operations and accepts input values, but does
not return a value and cannot be used in
expressions

New Perspectives on Microsoft Office Access 2007 5


Modules XP

New Perspectives on Microsoft Office Access 2007 6


Modules XP

• Declarations section
• Standard module
• Public procedure
• Class module
• Local procedure
• Private procedure

New Perspectives on Microsoft Office Access 2007 7


Using an Existing Procedure XP

New Perspectives on Microsoft Office Access 2007 8


Creating a New Standard Module XP

• Click the Create tab on the Ribbon


• In the Other group on the Create tab, click the
arrow on the New Object button (with the
ScreenTip “New Object: Macro,” “New Object:
Module,” or “New Object: Class Module,”
depending on which option was last chosen), and
then click Module

New Perspectives on Microsoft Office Access 2007 9


Creating a New Standard Module XP

New Perspectives on Microsoft Office Access 2007 10


Creating a Function XP

• Each function begins with a Function statement


and ends with an End Function statement
– Parameter
– Argument

New Perspectives on Microsoft Office Access 2007 11


Testing a Procedure in the XP
Immediate Window
• In the Code window, click View on the menu bar,
and then click Immediate Window to open the
Immediate window
• Type a question mark (?), the procedure name,
and the procedure’s arguments in parentheses. If
the argument contains a string of characters,
enclose the value in quotation marks
• Press the Enter key and verify the displayed
answer

New Perspectives on Microsoft Office Access 2007 12


Testing a Procedure in the XP
Immediate Window

New Perspectives on Microsoft Office Access 2007 13


Creating an Event Procedure XP

New Perspectives on Microsoft Office Access 2007 14


Designing the Event Procedure XP

New Perspectives on Microsoft Office Access 2007 15


Adding an Event Procedure to a XP
Form or Report
• Open the form or report in Design view, select the
control whose event property you want to set, open the
property sheet for the control, and then click the Event
tab in the property sheet
• Click the desired event property box, click its Build
button, click Code Builder in the Choose Builder dialog
box, and then click the OK button
• Enter the subroutine statements in the Code window
• Compile the procedure, fix any statement errors, and
then save the event procedure

New Perspectives on Microsoft Office Access 2007 16


Adding an Event Procedure to a XP
Form or Report

New Perspectives on Microsoft Office Access 2007 17


Compiling Modules XP

• The process of translating modules from VBA to


a form your computer understands is called
compilation; you say that you compile the
module when you translate it
• When you run a procedure for the first time,
Access compiles it for you automatically and
opens a dialog box only when it finds syntax
errors in the procedure

New Perspectives on Microsoft Office Access 2007 18


Adding a Second Procedure XP
to a Class Module

New Perspectives on Microsoft Office Access 2007 19


Adding a Second Procedure XP
to a Class Module

New Perspectives on Microsoft Office Access 2007 20


Changing the Case of a Field Value XP

• StrConv function
• wvProperCase constant

New Perspectives on Microsoft Office Access 2007 21


Hiding Controls and Changing a XP
Control’s Color

New Perspectives on Microsoft Office Access 2007 22


Hiding Controls and Changing a XP
Control’s Color

New Perspectives on Microsoft Office Access 2007 23

You might also like