OpenADODB




Public Sub OpenDB(cn As ADODB.Connection, _
rs As ADODB.Recordset, _
strDBName As String, _
strTableName As String, _
strSelection As String, _
strPath As String)

Dim strConnect As String
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
strConnect = strConnect & strPath & "\" & strDBName

cn.CursorLocation = adUseClient
cn.Open strConnect
rs.CursorType = adUseClient
rs.LockType = adLockPessimistic
rs.Source = "SELECT " & strSelection & " FROM " & strTableName
rs.ActiveConnection = cn
rs.Open
End Sub

'#########

'#Example#

'#########

Option Explicit
Dim WithEvents rsSM As ADODB.Recordset
Dim WithEvents cnSM As ADODB.Connection
Private Sub Form_Load()
Dim strDB As String
Dim strTable As String
Dim strSelection As String
Dim strPath As String

strDB = "Shipping.mdb"
strTable = "tblDriverLog"
strSelection = "*"
strPath = App.Path
Set cnSM = New ADODB.Connection
Set rsSM = New ADODB.RecordSet
OpenDB cnSM, rsSM, strDB, strTable, strSelection, strPath
End Sub

Inputs:
This sub has the following parameters:
cn is the name of the connection,
rs is the name of the recordset,
strDBName is the name of the database,
strTableName is the name of the table,
strSelection is the name of of the fields,
strPath is the path To the database

Assumes:
In order for this code to work,
the Microsoft ActiveX Data Objects 2.0
Library reference needs to be checked.










( openadodb.html )- by Paolo Puglisi - Modifica del 17/12/2023