Open In App

VarType Function in MS Access

Last Updated : 14 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we are going to cover VarType function in MS Access and will cover variable type of VarType function and also we will cover the return type of each VarType function. Let's discuss one by one.

VarType :

It is the function in Microsoft Access is used to return an Integer indicating the subtype of a variable. In MS Access VarType() function returns an Integer and that integer indicating the subtype of a variable like if a value is an integer value then it will simply return 2 for integer.  

Syntax :
VarType ( varname )
  • Parameter  -This method accepts one parameter as mentioned above and described below.
  • varname -It is a variant containing any variable except a variable of a user-defined type.

Returns : It Returns an Integer for denoting the variable type. Example -

In this example, you can see all Var Type name and return value of each type. Also, Description of each Variable Type for better understanding.

Constant(Var Type Name)Description Of Variable TypeReturn Value
EmptyEmpty (uninitialized)0
NullNull (no valid data)1
IntegerInteger2
LongLong integer3
SingleSingle-precision floating-point number4
DoubleDouble-precision floating-point number5
CurrencyCurrency value6
DateDate value7
StringString8
ObjectObject9
ErrorError value10
BooleanBoolean value11
VariantVariant (used only with arrays of variants)12
DataObjectA data access object13
DecimalDecimal value14
ByteByte value17
UserDefinedTypeVariants that contain user-defined types36
ArrayArray8192

Example -

Let's consider a long integer value like 80000 then if you will use the VarType function then it will return 3 for long integer.

SELECT VarType(80000);

Output -

3  

Example - 

Let's consider a Decimal value like 11.1 then if you will use the VarType function then it will return 14 for Decimal.

SELECT VarType(11.1);

Output  :

14

Example -

Let's consider a String value like Geeksforgeeks then if you will use the VarType function then it will return 8 for String.

SELECT VarType( "Geeksforgeeks");

Output :

8

Example -

Let's consider a Date value like #11/09/20# then if you will use the VarType function then it will return 7 for Date value.

SELECT VarType( #11/09/20# );

Output -

7

Implementation of VarType function in Visual Basic :

Let's implement the VarType function in Visual basic for application. A program to demonstrate the VarType function to determine the subtype of a variable.

Example -

Dim StrVar, DateVar, IntVar, MyFun

StrVar     =  "Ashish"
DateVar =  #11/09/20# 
IntVar     =  500

MyFun   =  VarType(DateVar)   ' Returns 7.
MyFun     =  VarType(StrVar)    ' Returns 8.
MyFun   =  VarType(IntVar)    ' Returns 2.



Next Article
Article Tags :

Similar Reads