Solved

Can't open a Recordset?

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 67
How to split this in C++ 4 78
parentbit challenge 3 52
Non-recursive backtracking, using a stack 1 53
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

10 Experts available now in Live!

Get 1:1 Help Now