ADODB Connection Module

Save Connection Procedures & functions in a public module that helps simplify the connection procedures.
-Selva V Pasupathy, HSBC Global Resourcing, Hyderabad

Option Explicit
Public i, j, k As Integer
Public objConn As New ADODB.Connection
Public objrs As New ADODB.Recordset
Public strConn, dbSource, strSQL  As String
Sub Get_Connection()
Set objConn = New ADODB.Connection
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source='" & BrowseFileName & "'"
    objConn.Open strConn
End Sub
Sub Get_RecordSet(ByRef strSQL As String)
Set objrs = New ADODB.Recordset
    objrs.Open strSQL, objConn, adOpenStatic, adLockOptimistic
End Sub
Public Function BrowseFileName() As String
    Dim dlgOpen As FileDialog
    Dim name As String, fileName As String, target As String
    Dim lngIndex As Long

    Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
    With dlgOpen
        .AllowMultiSelect = True
        .Show
        BrowseFileName = .SelectedItems(1)
    End With
End Function

Leave a Comment

You must be logged in to post a comment.