VB Tutorial-Connect VB Application With MS Access Through Coding
VB Tutorial-Connect VB Application With MS Access Through Coding
Author
D BESCHI ANTONY
([email protected])
Introduction
This tutorial helps to connect the visual basic applications with the MS-Access database
using coding. Once the connection is made with the database in this way that can be
used within the application scope. This tutorial is made with the visual representations of
each step to make connection.
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\workspace\Learning\dbfolder \test.mdb;Persist Security Info=False
Sub Main()
// Defining the connection variable
Set CnnStr = New ADODB.Connection
CnnStr.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\workspace\Learning\dbfolder\test.mdb;Persist Security
Info=False"
Note : In case, f your application is going to be shifted to the different computer, the
path in the connection string will not refer to the database so you need you use relative
path instead of absolute path. The connection string will look like this
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path &
"\dbfolder\test.mdb;Persist Security Info=False"
In case if you use password protected database. The connection string will be
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path &
"\dbfolder\test.mdb;Persist Security Info=True;Jet OLEDB:Database
Password=yourpassword"
4. Finally you have to set up the startup function for your application that can be
achieved by Right clicking on the project and select the your application name
properties. And select the module main sub routine as your startup function
With these settings you have reached your goal. Hence forth you can easily
communicate with your backend storage (MS-Access) without any difficulties.
Creating an Example
This example shows just the methods or the way in which the database connection can
be used.
To Retrive records from database
Public Function isValidUser(sUserName As String, sPassword As String)
As Boolean
Further reading is needed to acquire the knowledge about the cursors and record sets
Your suggestions and corrections are welcomed! You can reach me by mailing to me
to [email protected]