The VBA Editor Explained

In this blog post, we explain how the VBA editor works.

There are four main areas of the editor that you need to know about.

 The Code Window

7

The Code Window is where all your VBA code will be written. It has syntax highlighting, which means keywords in VBA, – such as Function, CStr, Return and others – will all appear in one colour, numbers in another colour, punctuation, comments and strings in yet other colours. It looks more appealing and makes reading lines of code much easier.

 

Another feature of the editor is called Code Completion.  This is a useful feature; when you type in commands the editor will display possible values which it believes you may need.  For example if you type Dim a As Str_ this ———>will happen.  8

Project Explorer Tree

The project explorer shows you all the modules available in your database and any add-ins or libraries you’ve included. Modules are kept in three areas:* Microsoft Office Access Class Objects* Standard Modules

 

* Class Modules

 

 

 9

Microsoft Office Access Class Objects

These are VBA modules that are owned by (or children of) Forms and Reports. Their name will always be prefixed with “Form_” or “Report_”.  In these modules, you will put all the event code that makes your forms and reports perform essential actions – like opening and closing. Unlike Standard Modules code in these modules is not normally available outside the form. This means that any code written here cannot be seen by other modules and we describe these modules as private.

Standard Modules

Standard modules contain code which may be accessed by any of the module types.  In Standard Modules, will go code that doesn’t belong in forms or reports, for example a library of business rules or constants and types which are used by Forms and Reports.  By default anything written in here is available anywhere else in the project – this is known as global scope (public as opposed to private).

Class Modules

Each Class Module contains code that revolves around a Class, which is a type of data-type or object. By default, anything written here is available elsewhere in the project.

Properties Window

The properties window is available in two places; the first is in the Form Design window docked to the right. The second is usually in the bottom left in the VBA Editor.  If it’s not there, you can bring it up by pressing F4 or using the view menu.

10

 11

Immediate Window

The immediate window is located at the bottom of the screen and is the big blank window that says immediate in the title.

Using this window, you can test code snippets, test out your functions directly rather than through a form’s button, and also debug your code.

Here is a small introduction. Try typing print now() and see what date and time come up. Then try Print InputBox(“what’s your name?”)

12

There are a number of useful tools available in the Visual Basic Editor. Make sure you understand them and your coding will get a lot simpler, a lot more quickly.

Related Posts

Basic Tools for Writing Code
Compilation Explained
Debugging
Immediate Window
Opening The VBA Editor
Visual Basic Editor Options

Leave a Reply

Your email address will not be published. Required fields are marked *

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube