Results 1 to 4 of 4

Thread: Maybe it's better asked over here *RESOLVED*

  1. #1

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186

    Maybe it's better asked over here *RESOLVED*

    Here's my code for those who haven't seen it:
    VB Code:
    1. Option Explicit
    2.  
    3. Private cn As ADODB.Connection
    4. Private rs As ADODB.Recordset
    5.  
    6. Private Sub Form_Load()
    7.  
    8. Set cn = New ADODB.Connection
    9.  
    10. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    11. "Data Source= C:\mydatabase.mdb"
    12.  
    13. cn.Open
    14.  
    15. Set rs = New ADODB.Recordset
    16.  
    17. rs.Open "SELECT * FROM game WHERE hometeamid = '" & Text1.Text & "' OR awayteamid = '" & Text1.Text & "'"
    18.  
    19. rs.MoveFirst
    20. Do Until rs.EOF = True
    21.     Combo1.AddItem rs.Fields("gameid")
    22.     rs.MoveNext
    23. Loop
    24.  
    25. rs.MoveFirst
    26.  
    27. End Sub
    I get an error message on my SELECT statement saying:
    Code:
    Run-time error '3709';
    
    The connection cannot be used to perform this operation. It is either
    close or invalid in this context.
    Anyone have an idea as to why? Am I doing something wrong when I open the recordset?
    Last edited by run_GMoney; Jun 3rd, 2003 at 04:09 PM.
    Place Your VBForums Ad Here

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    Maybe this will work

    dim sql as string

    sql = "SELECT * FROM game WHERE hometeamid = '" & Text1.Text & "' OR awayteamid = '" & Text1.Text & "'"


    rs.Open sql, Cn, adOpenKeyset, adLockReadOnly, adCmdText

  3. #3
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    You didn't associate a valid cn object for your rs. After you add you select statement add the cn object and any other params you need.

  4. #4

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Yeah actually I should have altered my subject on the thread. I figured that out about 3 hours ago. Thanks for the reply though
    Place Your VBForums Ad Here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width