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

From the help system, "ADO Error Codes":
*adErrInvalidConnection 3709
0x800A0E7D
The application requested an operation on an object with a reference to a closed or invalid Connection object. *

So that tells me you have either a) not properly opened your connection object (but we can't see what's in the "OpenCon" subroutine) or b) not properly defined and/or instantiated your connection object.

It is entirely possible that the problem is in your OpenCon subroutine. Double check that you aren't running into a variable scope issue.

Hope that helps! Good luck!

This article has been dead for over six months. Start a new discussion instead.