MS Access 2010 VBA tutorial- Operators

VBA Operators

When writing VBA expressions, you will need to use VBA operators. In an expression, there are operands and operators to produce a final value. The followings are commonly used operators in VBA programming:

-Assignment Operator

The assignment (=) is used to assign value to variable.


Dim x As Integer x=10  

-Arithmetic operators

The arithmetic operators (+,-,*, /, mod, ^) are used to do math operations such as addition, subtraction, multiplication, division, modulus of division, and exponential computation. Example: Dim x As Integer Dim y As Integer Dim sum As Integer   x=10 y=20 sum=x+y
MsgBox “Total=” & sum  

-Logical operators

The logical operators are used to do logical operations such and, or, exclusive or, and not. The most commonly used VBA logical operators are And, Or, Xor, and Not.
The Not operatorneeds only one operand. It used to contrast the value of the operand.



y=Not x 'then y get False value


-String concatenation operator (&)

It is used to concatenate sub-strings.

MsgBox “Lastname: “ & “Yuk”  

-Line feed operator (Vbcrlf)

This operaor is used to make a new line in the text output.

Msgbox “Lastname:”& “Yuk” & Vbcrlf & “Firstname:” &”Dara”

-Underscore operator(_)

The underscore operator is used to continue code when it is too long to write it on a single line.
 printval End Sub  

-Comparison operators (=,>,<,>=,<=,<>)

The operators are used to compare values. The results from using comparison operators are true or false.


Dim f As Boolean
f=10>5 Msgbox f  

-Comma operator (,)

The comma operator is used to separate variables declare.
Dim x, y, z As Single


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.