Access VBA Macro Programming

(Joao Candeias) #1

You can use theIsNumericfunction to test if the value of a variant is a number—it
returns true or false (nonzero or zero).


Sub TestNumeric()
temp="richard"
MsgBox IsNumeric(temp)
End Sub


This will give the result False.


Date/ Time Values Stored in Variants


Variant variables can also contain Date/Time values. This is a floating point number—the
integer part represents the days since 31-Dec-1899, and the decimal part represents the hours,
minutes, and seconds expressed as a proportion of 24 hours. For example, 37786.75
represents 14-June-2003 at 18:00. The difference between 31-Dec-1899 and 14-June-2003 is
37,786 days, and 0.75 of 24 hours is 18 hours.
Adding or subtracting numbers adds or subtracts days. Adding decimals increases the time
of day—for example, adding 1/24 (0.0416) adds one hour. A number of functions handle date
and time, as explained in Chapter 5.
Note that the interpretation of day and month is dependent on the Regional Options
settings within the Windows Control Panel. If you set your date to mm/dd/yy in Regional
Options, this will be the default interpretation of day and month.
Just as you can useIsNumericto determine if there is a numeric value, you can use the
IsDatefunction to determine if there is a date value.


temp = "01-Feb-2009"
MsgBox IsDate(temp)


This will return True (nonzero).


Empty Value


A variant that has not had a variable assigned to it will have an empty value. You can test for
this using theIsEmptyfunction.


MsgBox IsEmpty(MyTest)


This example will return True (nonzero) because MyTest has not been assigned a value.


Null Values


A variant can contain a special value of Null. The Null value is used to indicate unknown or
missing data. Variables are not set to Null unless you write code to do this. If you do not use
Null in your application, you do not have to worry about Null.


Chapter 2: Variables, Arrays, Constants, and Data Types 19

Free download pdf