Connect database using ADODB connection with module
This tutorial I will show you how to connect the database access using
ADODB or ActiveX Data Object Database Connection integrated with forms and
module components.
Step 1:
Add a Form and Module, like this
Step 2:
Select the Modules Folder and Double Click the
Module1, it will show you like this
Step 3:
Before you type the code, make sure to check the Project Reference of Microsoft
ActiveX Data Objects 2.0 Library then click Ok button, like this
Step 4:
Then type the following code under the Option Explicit.
You can choose any of this technique to connect a database.
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public Sub Connect()
Set con = New ADODB.Connection
con.CursorLocation = adUseClient
con.ConnectionStringProvider = "Microsoft.Jet.OLEDB.4.0;Data
Source=" & App.Path & "\Database.mdb" &
";Persist Security Info=False"
con.Open
End Sub
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public strConnect As String
Public Sub Connect()
Set con = New ADODB.Connection
con.CursorLocation = adUseClient
con.ConnectionString = strConnect
con.Open
End Sub
Public Function strConnect As String
strConnect = “Provider = Microsoft.Jet.OLEDB.4.0;Data Source="
& App.Path & "\Database.mdb" & ";Persist Security
Info=False”
End Sub
Step 5:
Call the module in your Form_Load Event, like this
Private Sub Form_Load()
Module1.Connect
Sub
So, there you go. If something errors appear, check your database connection or the path of your access file.
cheers!! enjoy! :)
Connect database using ADODB connection with module
Reviewed by code-dev
on
4:22 PM
Rating:
No comments: