Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't open a Recordset?

Posted on 2006-11-17
1
Medium Priority
?
246 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
[X]
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
1 Comment
 
LVL 3

Accepted Solution

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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…
Progress

636 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