troubleshooting Question

.Open method of ADODB recordset gives error

Avatar of vj_mi
vj_mi asked on
Visual Basic Classic
3 Comments1 Solution381 ViewsLast Modified:

I have written a generic function that will; return me ADODB recordset in VB6. But when I set properties and call the below function, the .Open method of the ADODB recordset gives me error: Automation Error: Unspecified error. Below is the code. Any reasons?

Public Function GetTableData() As ADODB.Recordset

    Dim Rs As ADODB.Recordset
    Dim strSQL As String
    Dim objConnection As ADODB.Connection
    Dim objConnect As ConnectionDLL.clsConnection
    On Error GoTo Err_Hnd
    Set Rs = New ADODB.Recordset
    Set objConnection = New ADODB.Connection
    Set objConnect = New ConnectionDLL.clsConnection
    objConnect.INIFilePath = gstrINIFilePath
    objConnection.ConnectionString = objConnect.CreateConnectionString(gstrINIFile)
    objConnection.CursorLocation = adUseClient
    If Trim$(m_strFields) = "" Then
        strSQL = "Select * From " & m_strTableName
        strSQL = "Select " & m_strFields & " From " & m_strTableName
    End If
    If Trim$(m_strPredicate) <> "" Then
        strSQL = strSQL & " Where " & m_strPredicate
    End If
    If Trim$(m_strOrderBy) <> "" Then
        strSQL = strSQL & " Order by " & m_strOrderBy
    End If
    Rs.Open strSQL, objConnection, adOpenStatic, adLockReadOnly
    Set GetTableData = Rs
    GoTo Exit_Routine
    Err.Raise Err.Number, "clsData.GetTableData", "Error occurred while reading data."
    GoTo Exit_Routine
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros