5 Replies - 1495 Views - Last Post: 09 April 2013 - 10:18 PM Rate Topic: -----

#1 kaye143  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 29
  • Joined: 08-January 11

run time error '3709'

Posted 03 April 2013 - 09:18 PM

"run time error'3709' The connection cannot be used to perform this operation. It is either closed or invalid in this context."
My simple program where I connect ms access to vb6. I created log in button but when I try to log in I get the error and the codes turns yellow.
 rs.Open "select * from baliw where username='" & Text1.Text & "' and password='" & Text2.Text & "'", con, adOpenStatic, adLockOptimistic


Private Sub Command1_Click()
      
   Set rs = New Recordset
    rs.Open "select * from baliw where username='" & Text1.Text & "' and password='" & Text2.Text & "'", con, adOpenStatic, adLockOptimistic
    
    If rs.EOF = False Then
        If rs!username = "admin" Then
            Form2.Show
            Unload Me
        ElseIf rs!username = "hr" Then
            Form3.Show
            Unload Me
        Else
            Form4.Show
            Unload Me
        End If
    
    Else
        MsgBox "Incorrect username/password", vbCritical, "Login Error"

End If
End Sub



thank you in advance! :)/>

This post has been edited by kaye143: 03 April 2013 - 09:24 PM


Is This A Good Question/Topic? 0
  • +

Replies To: run time error '3709'

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: run time error '3709'

Posted 04 April 2013 - 01:41 AM

Where do you open the connection to the DB?
Was This Post Helpful? 0
  • +
  • -

#3 kaye143  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 29
  • Joined: 08-January 11

Re: run time error '3709'

Posted 05 April 2013 - 09:16 PM

This is my module connection.
Public con As ADODB.Connection
Public rs As New Recordset

Sub Main()
	Set con = New Connection

	Con.Open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbsample.mdb"
	Form1.Show
	End Sub 

	

Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: run time error '3709'

Posted 05 April 2013 - 11:43 PM

have you stepped through this in debug mode and determined that the connection is actually open?
Was This Post Helpful? 1
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: run time error '3709'

Posted 06 April 2013 - 10:27 AM

Ok. You could be getting this problem because the connection is invalid, or because you closed it somewhere without realizing it. The latter is more probable. One of the main reasons that it can be invalid is because you are using both ADO and DAO, and you think you have an ADO recordset but really have a DAO recordset. Some versions of DAO don't have a connection object.
Was This Post Helpful? 1
  • +
  • -

#6 kaye143  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 29
  • Joined: 08-January 11

Re: run time error '3709'

Posted 09 April 2013 - 10:18 PM

I already found out my problem ,just forgot to put "" on my filename >_<.. tnx for the help though :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1