Solved

Can't open a Recordset?

Posted on 2006-11-17
1
224 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bunnyEars challenge 6 102
count7 challenge 12 103
changePi Challenge 15 104
Filename to be appended with DateTimeof Download 3 46
A short article about a problem I had getting the GPS LocationListener working.
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.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now