8 Replies - 5265 Views - Last Post: 21 September 2012 - 07:19 AM Rate Topic: -----

#1 thefifthhjohn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-July 12

run time error 3709

Posted 20 August 2012 - 06:18 AM

please help me I'm having error in rs.Open "SELECT * FROM [tbladmin] WHERE [username]= '" & txtUsername.Text & "'", con, adOpenStatic, adLockOptimistic I think my code is right I dunno where I went wrong.
Dim strUserName As String, strPassword As String
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub cmdlogin_Click()
OpenCon
rs.Open "SELECT * FROM [tbladmin] WHERE [username]= '" & txtUsername.Text & "'", con, adOpenStatic, adLockOptimistic
        
        If rs.RecordCount <> 0 Then
            If rs![Password] = txtPassword.Text Then
                If rs![user_type] = "Principal" Then
                        
                    MsgBox "The Principal has login", vbOKOnly + vbInformation, "LOGIN"
                    
                        frmMain.Transaction.Visible = True
                        frmMain.Maintenance.Visible = True
                        frmMain.Reports.Visible = True
                        frmMain.Exit.Visible = True
                        frmMain.Others.Visible = True
                        frmMain.Files.Visible = True
                        Login1 = 1
                        'frmMain.Text3 = Text1.Text
                        'frmMain.Text4 = TimeValue(Now)
                    End If
           End If
      End If
End Sub

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: run time error 3709

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: run time error 3709

Posted 21 August 2012 - 12:42 PM

the error says all. either you dont open your connection or the string for the connection is invalid. if you could show us the code where you open the connection we may give you better help
Was This Post Helpful? 0
  • +
  • -

#3 thefifthhjohn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 13-July 12

Re: run time error 3709

Posted 25 August 2012 - 06:53 PM

View Postraziel_, on 21 August 2012 - 12:42 PM, said:

the error says all. either you dont open your connection or the string for the connection is invalid. if you could show us the code where you open the connection we may give you better help

Public con As New ADODB.Connection
Public Sub OpenCon()
    Set con = New ADODB.Connection
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\database\enrollment.mdb"
End Sub

Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: run time error 3709

Posted 26 August 2012 - 02:10 AM

Try checking if the connection is actually opened (think it's the State property).
Was This Post Helpful? 0
  • +
  • -

#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 31 August 2012 - 04:21 PM

This is a theory, not for sure. Try removing the "New" from your "As New" in your line 1. If it solves your problem, I'll tell you why I think so. In any case, it shouldn't be there, so remove it.
Was This Post Helpful? 0
  • +
  • -

#6 leixnt  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 24-July 11

Re: run time error 3709

Posted 17 September 2012 - 08:06 PM

the code should be like this to run normally

Dim strUserName As String, strPassword As String
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset


Public Sub OpenCon()
    if con.state = 0 then
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\database\enrollment.mdb"
    end if
End Sub

Private Sub cmdlogin_Click()
OpenCon
rs.Open "SELECT * FROM [tbladmin] WHERE [username]= '" & txtUsername.Text & "'", con, adOpenStatic, adLockOptimistic

        If rs.RecordCount <> 0 Then
            If rs![Password] = txtPassword.Text Then
                If rs![user_type] = "Principal" Then
                         
                    MsgBox "The Principal has login", vbOKOnly + vbInformation, "LOGIN"
                        frmMain.Transaction.Visible = True
                        frmMain.Maintenance.Visible = True
                        frmMain.Reports.Visible = True
                        frmMain.Exit.Visible = True
                        frmMain.Others.Visible = True
                        frmMain.Files.Visible = True
                        Login1 = 1
                        'frmMain.Text3 = Text1.Text
                        'frmMain.Text4 = TimeValue(Now)
                    End If
           End If
      End If
End Sub




Was This Post Helpful? 0
  • +
  • -

#7 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 20 September 2012 - 03:08 PM

leixnt, how is your code different from the OP's?
Was This Post Helpful? 0
  • +
  • -

#8 Bertdecode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-September 12

Re: run time error 3709

Posted 20 September 2012 - 06:36 PM

Try This.

Dim strUserName As String, strPassword As String
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

 

 

Public Sub OpenCon()
    Set con=new ADODB.Connection
    if con.state = 0 then

    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\database\enrollment.mdb"

    end if

End Sub

 

Private Sub cmdlogin_Click()
Set rs=new ADODB.Recordset
OpenCon

rs.Open "SELECT * FROM [tbladmin] WHERE [username]= '" & txtUsername.Text & "'", con, adOpenStatic, adLockOptimistic

 

        If rs.RecordCount <> 0 Then

            If rs![Password] = txtPassword.Text Then

                If rs![user_type] = "Principal" Then

                          

                    MsgBox "The Principal has login", vbOKOnly + vbInformation, "LOGIN"

                        frmMain.Transaction.Visible = True

                        frmMain.Maintenance.Visible = True

                        frmMain.Reports.Visible = True

                        frmMain.Exit.Visible = True

                        frmMain.Others.Visible = True

                        frmMain.Files.Visible = True

                        Login1 = 1

                        'frmMain.Text3 = Text1.Text

                        'frmMain.Text4 = TimeValue(Now)

                    End If

           End If

      End If

End Sub



Was This Post Helpful? 0
  • +
  • -

#9 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 21 September 2012 - 07:19 AM

In other words, do as I suggested, or just copy Bert's code since he was kind enough to do it for you. :) If that doesn't work, we'll look at something else.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1