VarType
Using the VARTYPE Function
In this tutorial you will learn how to use the VarType Function.
The VarType function returns an Integer indicating the subtype of a variable.
=VarType( varname )
varname is a Variant containing any variable except a variable of a user defined type
If we wanted to check the Type of a value we can pass it to the following, say it was the String "Alex"
The result is 8.
The return values are:
| Constant | Value | Description |
| vbEmpty | 0 | Empty (uninitialized) |
| vbNull | 1 | Null (no valid data) |
| vbInteger | 2 | Integer |
| vbLong | 3 | Long integer |
| vbSingle | 4 | Single-precision floating-point number |
| vbDouble | 5 | Double-precision floating-point number |
| vbCurrency | 6 | Currency value |
| vbDate | 7 | Date value |
| vbString | 8 | String |
| vbObject | 9 | Object |
| vbError | 10 | Error value |
| vbBoolean | 11 | Boolean value |
| vbVariant | 12 | Variant (used only with arrays of variants) |
| vbDataObject | 13 | A data access object |
| vbDecimal | 14 | Decimal value |
| vbByte | 17 | Byte value |
| vbUserDefinedType | 36 | Variants that contain user-defined types |
| vbArray | 8192 | Array |
Query
The results using a Query would be
SELECT VarType("Alex");
FORM
In a Form you could set the Default Value of a Textbox to
=VarType("Alex")
VBA
In a Form add a TEXTBOX control and rename it "txtVarType", then you could add the following in the Load Event.
Private Sub Form_Load()
txtVarType = VarType("Alex")
End Sub
Courses
Access Expert 25
Search
You can find more about this by searching the website.
By: Alex Hedley
Click here to sign up for more FREE tips
|