From the course: Access: VBA

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Declare variables and require declaration before using

Declare variables and require declaration before using

From the course: Access: VBA

Start my 1-month free trial

Declare variables and require declaration before using

When you write Access VBA code, you'll often use variables to represent numbers, character strings, and objects. In this movie, I will show you how to define, or declare, those variables and reduce the likelihood of errors by requiring that you declare variables within a code module. I have opened the course database and I'll press Alt + F11 to move to the Visual Basic Editor. Now that I'm here, I can create a code module by going to the Insert menu and clicking Module and there is my code module. I'll go ahead and start a subroutine. So, I'll type "Sub" and I'll call it CalcComm, and that's just short for calculate commission. I'm not giving it any arguments, so I'll type an open and close left parenthesis and press Enter a couple of times to give me the End Sub line and also some room to work. I'll start by declaring a variable using the Dim keyword. What I'm doing is declaring, or dimensioning, a variable and providing information about it. So, if I were to have curValue as…

Contents