Results 1 to 4 of 4

Thread: To pass the conn object or not? That is the question.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking To pass the conn object or not? That is the question.

    With this code, how do I pass the conn object to another class module?
    The name of the function that needs to receive the conn object is
    Code:
    Public Function Get_Search_RS(conn As ADODB.Connection, rsRecordset As ADODB.Recordset, strTitle As String, strCat As String, strFileX As String, strFileName As String) As String

    Code:
    Public Sub GetConn2()
        Set conn = New ADODB.Connection
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Sms001\Shared\web\Internet\Graphic_Search\dbGraphics.mdb;Persist Security Info=False"
        conn.CursorLocation = adUseClient
        conn.Open
            
    End Sub

  2. #2
    Addicted Member Nice's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    144

    Cool

    how abt using a property for the connection object and then use it in the class module as normal?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    Not sure what you mean? Can you show me an example please?

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    They may help ya, I pass a connection object, and return a recordset. This is a class mod:

    Code:
    Public Function GetAllStates(ByRef objConn As ADODB.Connection) As Recordset
        '// Declare local objects
        Dim objRS As New ADODB.Recordset
        
        '// Setup error handling
        On Error GoTo GetAllStates_EH
        
        '// Set recordset cursor location and open recordset
        objRS.CursorLocation = adUseClient
        objRS.Open "up_select_state_name", objConn, adOpenStatic, adLockReadOnly, adCmdStoredProc
        
        '// Disconnect recordset
        Set objRS.ActiveConnection = Nothing
        
        '// Return with the recordset
        Set GetAllStates = objRS
        Set objRS = Nothing
        
        '// All was successful, exit function
        On Error GoTo 0
        Exit Function
        
    GetAllStates_EH:
        Set GetAllStates = Nothing
        Set objRS = Nothing
        On Error GoTo 0
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width