VBA tutorial-Access 2007: Visual Basic for Applications

What is VBA ?

VBA stands for Visual Basic For Applications. VBA was created by Microsoft and is used in many Microsoft products such as Ms. Word, Ms. Excel, Ms. Access, Ms. Outlook, etc. VBA was created in the purpose of helping Microsoft users in extending their ability by writing code to manage data in more efficient and effective way.

Where can you write the VBA code? Simply you can write your VBA code by using Visual Basic Editor. To open Visual Basic Editor, after opening a database, you can press Alt with F11. For a database file (never has had VBA code before) it looks like this:

VBA Editor


Vandet comment


i have 2 tables. one table store address like this:
001- st. A, sk. B, kh.
002- sk. E, kh. F.
another table store condition:
01- st.
01- sk.
01- kh.
02- sk.
02- kh.
i want to check address 001 go to which condition ? 01 or 02?
can u have me, teacher?
if have any code please show me please .
i use msaccess 2003, vba code.
Thanks teacher.

Dara comment


Option Explicit
Dim Cn as New ADODB.Connection
Private Sub_Form_Load()
Cn.Open "Provider=SQLOLEDB; Data Source=ServerName; Initial Catalog=DatabaseName;UserID=UserName; Password=Passw"
End Sub
You will need to replace ServerName with the name of your server (installed SQL Server), DatabaseName withe the name of your data file that you want to connect to, UserName with the name of the user to login to SQL Server, and Passw with the password used to login to SQL Server.

sophea comment


Hello! sirs I want to know code VBA in MS.access connect to MS.SQL Server for Back end.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.