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

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: