Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Can't open a Recordset?

Posted on 2006-11-17
1
233 Views
Last Modified: 2010-04-16
I am trying to open a recordset right after opening a connection. I keep getting the error message:

  "The connection cannot be used to perform this operation. It is either closed or invalid in this context.

Here is my code.

Public Function OpenDBConnection() As Boolean
    Dim strConnectString As String
   
    On Error GoTo ErrProc
   
    strConnectString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "\PT.mdb;Exclusive=1;Uid=admin;Pwd="
   
    If cn.State = 0 Then
        cn.Open strConnectString
        OpenDBConnection = True
    Else
        cn.Close
        cn.Open
        OpenDBConnection = True
    End If
   
    Exit Function
   
ErrProc:
    MsgBox Err & ": " & Error
End Function
'
'
'
Private Sub LoadEmployees()
    Dim rs As New ADODB.Recordset
   
    On Error GoTo ErrProc
   
    If OpenDBConnection Then
        rs.Open "tblEmployee", cn, adOpenKeyset, adLockReadOnly   <<<<<<<<<< ERROR MESSAGE >>>>>>>>>>
   
        If rs.RecordCount > 0 Then
            Do While Not rs.EOF
                cmbEmployee.AddItem rs!empLastName & ", " & rs!empFirstname
                rs.MoveNext
            Loop
        End If
    End If
   
    Exit Sub

ErrProc:
    MsgBox Err & ": " & Error
End Sub


I know the connection is open but I don't know why I can't open the recordset.

-Blake
0
Comment
Question by:BlakeMcKenna
1 Comment
 
LVL 3

Accepted Solution

by:
cdemir earned 500 total points
ID: 17971259
rs.Open "select * from tblEmployee", cn, adOpenKeyset, adLockReadOnly
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question