What is VBA Stand For?
There are many development programming which is used their environment to develop the applications such as web, mobile and even desktop application. So what is VBA and why it is still important for developers? VBA is standing for Visual Basic Application. You can find VBA code in any Microsoft Office Applications. The most usage of VBA application to work within nowadays business is Microsoft Excel Application and Microsoft Access Application.
What are the Variables in VBA?
Variables are being used in every programming language whether it is for desktop applications, web applications or even mobile applications. Those variables are performing specific tasks by the developers. Some programming may declare the variables with holding values which is called implicitly. For example, string name=”David”;. The other may declare only the variable name to use get input from users or other methods which is called explicitly. For example, string name;. Variable is specifically use to identify or store the value in the system memory and perform as specific task by the programming. VBA programming is also similar to other programming which its own datatypes such as string, integer, double, etc.
How To Declare Variable in VBA?
A little bit similar to Visual Basic.Net to declare the variable in VBA, it needs to use the Keyword Dim with following the Variable Name then using AS with data type without semicolon . As the example below:
Sub Connection() Dim con As String End Sub
Some of Data Types in Microsoft Access
As the real practice, we can classify the data type into two categories which is called Numeric Data Type and Non-Numeric Data Type.
Numeric Data Type and Its Values To Be Stored
|Type||Storage||Range of Values|
|Byte||1 byte||0 to 255|
|Integer||2 bytes||-32,768 to 32,767|
|Long||4 bytes||-2,147,483,648 to 2,147,483,648|
|Single||4 bytes||-3.402823E+38 to -1.401298E-45 for negative values 1.401298E-45 to 3.402823E+38 for positive values.|
|Double||8 bytes||-1.79769313486232e+308 to -4.94065645841247E-324 for negative values 4.94065645841247E-324 to 1.79769313486232e+308 for positive values.|
|Currency||8 bytes||-922,337,203,685,477.5808 to 922,337,203,685,477.5807|
|Decimal||12 bytes||+/- 79,228,162,514,264,337,593,543,950,335 if no decimal is use +/- 7.9228162514264337593543950335 (28 decimal places)|
Non-Numeric Data Type and Its Values To Be Stored
|Data Type||Bytes Used||Range of Values|
|String (fixed Length)||Length of string||1 to 65,400 characters|
|String (Variable Length)||Length + 10 bytes||0 to 2 billion characters|
|Boolean||2 bytes||True or False|
|Date||8 bytes||January 1, 100 to December 31, 9999|
|Object||4 bytes||Any embedded object|
|Variant(numeric)||16 bytes||Any value as large as Double|
|Variant(text)||Length+22 bytes||Same as variable-length string|
How To Write VBA in Microsoft Access
By going to your Form Object, drag and drop the control you want to write the command in VBA. Let’s use Command Button. Please drag into your Form, then Click on Cancel.
Then on your Form, please rename as “Admin Message” on the button then Right Click select Build Event —> select Code Builder
Then on Private Sub Command2_Click() you can start write your programming by declare your variable. For example
Option Compare Database Private Sub Command2_Click() Dim Admin_Message As String Admin_Message = "Welcome to Phsarit.org" MsgBox (Admin_Message), vbInformation End Sub
After you have declared as the example the above, please go back to your form design then select Form View. Click on your Command Button, the you should see the result as below: