Open In App

VarType Function in MS Access

Last Updated : 14 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
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 Type Return Value
Empty Empty (uninitialized) 0
Null Null (no valid data) 1
Integer Integer 2
Long Long integer 3
Single Single-precision floating-point number 4
Double Double-precision floating-point number 5
Currency Currency value 6
Date Date value 7
String String 8
Object Object 9
Error Error value 10
Boolean Boolean value 11
Variant Variant (used only with arrays of variants) 12
DataObject A data access object 13
Decimal Decimal value 14
Byte Byte value 17
UserDefinedType Variants that contain user-defined types 36
Array Array 8192

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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads