O'Reilly logo

Beginning Access™ 2007 VBA by Denise Gosnell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.4. Using Variables and Constants to Store Values

Now that you have a basic understanding of how to create procedures, turn your attention to learning how to use variables and constants in those procedures. Variables and constants can be used to store values that are used by your Access program. You have already seen a few examples of using variables to store values. This chapter covers variables in a bit more detail because they are so important to writing VBA code.

2.4.1. Types of Variables

Various types of variables can be declared and used in your procedures. The most common variables are probably String, Integer, Long, Currency, and Date, although other variables are also commonly used. The following table illustrates the various data types that are available in VBA and offers an explanation of the type of value each can store.

Figure 2.25. Figure 2-25
Data TypeWhat It Stores
AttachmentFile attachment
BooleanTrue or false
BytePositive integers from 0 to 255
CurrencyPositive and negative currency values with four decimal places
DateDate and time from 1/1/0100 to 12/31/9999
Double8-byte decimal values
HyperlinkURL for a hyperlink
Integer2-byte integers from −32,768 to +32,768
Long4-byte integers from −2 billion to +2 billion
ObjectAccess object reference
Single4-byte decimal values
Data TypeWhat It Stores
String (variable length)From 0 to 2 billion characters
String (fixed length)From ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required