53

Using Operators in VBA

Now that you have a pretty good understanding of the basics of VBA and how to write VBA code, it is time to examine all of the operators available in the VBA programming language. Though the number of operators is limited, they provide a plethora of functionality and are required quite often. As you saw in the previous lesson, operators serve many purposes, from arithmetic operations to logical operations. This lesson describes all of the operators available in the VBA language and provides examples of how they can be used.

LESSON SETUP

This lesson is designed to provide detailed information about the operators provided by VBA code. You should already be familiar with the basics of using operators from the previous lesson and know the basic parts of writing VBA code. Otherwise, this lesson does not require any other specific knowledge of Access.

VBA OPERATORS

As you have already seen, operators are a big part of the VBA programming language. Operators allow the user to perform a specific operation on one or more variables, depending on the type of operator that is used. For example, the + (addition) operator is used to add the values of two variables and returns the result. VBA offers close to 40 different operators, each of which serves a specific purpose, as shown in the next several sections.

Assignment Operators

VBA supports a number of assignment operators, but they are all derived from one basic assignment operator, which is the equal operator, denoted ...

Get Microsoft® Access® 2010 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.