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


(openadodb.html)- by Paolo Puglisi - Modifica del 25/3/2019