|
Microsoft
Office Training > Access
Training > Free
Computer Training > Access VBA Basics
Please feel free to use this content on your web site, but please include the links at the end.
ACCESS VBA BASICS
MODULES
There two types of modules
Standard module – a page that contains VBA that is accessible to all objects in a database.
Class Module – a page that is attached to every form and report. The code is only accessible to the form or report it is attached to.
Viewing Modules
To view standard modules – click on the module button in the database window
To view a class module, in design view, choose View | Code or ALT F11 (toggles)
ALT Q closes a module and returns to Access
PROCEDURES
A series of steps carried out in a specific order to achieve a desired result.
Each step in a procedure is a single line of code – a statement
Procedures are tied to events in your database. When the event happens (eg you open an object) Access calls the procedure.
There are two types of procedures:
Sub procedure:
Sub procedures are always contained within a pair of
Sub
Sub End
Sub procedures perform a task
Function procedure:
Function procedures perform calculations:
Function
End Function
A module may contain several procedures. Procedures within the same module are separated by a horizontal line.
THE VISUAL BASIC EDITOR
Project Explorer
Lists all the modules in the current database
Properties Window
Shows the properties of whatever is selected on the form or report
Immediate Window
Used for test code – sometimes referred to as the debug window
Code Window
Used for writing code. When you press enter at the end of a line of code, the VBE compiles the code to see whether it works
Object Library
When objects are made available VBA can use them. To use VBA to manipulate objects in Access, you have to make those objects available to VBA.
Tools | References shows a list of object libraries. The ones that are ticked are available to VBA
Object Browser
Allows you to see objects that are available in each library or all libraries
View | Object Browser
Microsoft Office Training with Blue Pecan Computer Training. Tailored Microsoft Access Training.
|