0

i am trying the code below to pull from access db, but getting error 91, please suggest how to remove the error.

Private Sub CommandButton1_Click()

    Dim con As ADODB.Connection

    Dim rs As ADODB.Recordset

    Dim strConn As String

    Set con = New ADODB.Connection

    con.Mode = adModeReadWrite

    If con.State = adStateClosed Then

      strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "C:\temp\db2.mdb;Persist    Security Info=False;"

      con.ConnectionString = strConn

      con.Open

    End If

    Dim startRow As Integer

    ***Set rs.ActiveConnection = con***

    rs.Open "select * from tbl_name"
    startRow = 3
    Do Until rs.EOF
       Cells(startRow, 4) = rs.Fields(0).Value
       rs.MoveNext
       startRow = startRow + 1
    Loop

    rs.Close
    Set rs = Nothing
    con.Close
    Set con = Nothing
End Sub
1
  • Thanks Joe, now i got it.. now its working.. Commented Dec 15, 2013 at 9:06

2 Answers 2

3

You call:

rs.ActiveConnection = con
rs.Open

without first creating an instance of the RecordSet:

Set rs = New ADODB.RecordSet
Sign up to request clarification or add additional context in comments.

Comments

0

I had this error while testing an application.

In my particular case, there was a problem with the Oracle Home used by the application. Therefore, the data source wasn't reachable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.