Help please. Error 3709: the connection cannot be used to perform the operation

Submitted by clydelee27 on
Help me please. I always get this error Error 3709:the connection cannot be used to perform the operation-it is either closed or invalid in this context. This is the highlighted code: rs.Open "SELECT * FROM users WHERE username = '" & LCase(txtUserName.Text) & "'", conn, adOpenStatic, adLockReadOnly This is the WHOLE code: MODULE:
  1. Option Explicit
  2.  
  3. Public conn As ADODB.Connection
  4.  
  5. Public Sub connect()
  6. Set conn = New ADODB.Connection
  7.     conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database.mdb;Persist Security Info=False"
  8. End Sub
  9.  
  10. Sub Main()
  11. connect
  12. frmLogin.Show
  13. End Sub
============================================== frmLogin codes:
  1. Dim ctr As Byte
  2. Private Sub cmdCancel_Click()
  3. End
  4. End Sub
  5.  
  6. Private Sub cmdOK_Click()
  7.  
  8.     Dim rs As New ADODB.Recordset
  9.  
  10.     rs.Open "SELECT * FROM users WHERE username = '" & LCase(txtUserName.Text) & "'", conn, adOpenStatic, adLockReadOnly
  11.     If rs.RecordCount <> 0 Then
  12.         If LCase(txtPassword.Text) = rs!password Then
  13.  
  14.             MsgBox "Username and Password Succesful!"
  15.            
  16.            
  17.         Else
  18.        
  19.             MsgBox "Invalid Password, Try again!", vbCritical, "Warning"
  20.             txtUserName.Text = ""
  21.             txtPassword.Text = ""
  22.             txtUserName.SetFocus
  23.             ctr = ctr + 1
  24.         End If
  25.     Else
  26.         MsgBox "Invalid Login, Try again!", vbCritical, "Warning"
  27.         txtUserName.Text = ""
  28.         txtPassword.Text = ""
  29.         txtUserName.SetFocus
  30.        ctr = ctr + 1
  31.        End If
  32.         If ctr = 3 Then
  33.                     objLock (True)
  34.                 MsgBox "You have attempted to Login 3 Times in the system. " & _
  35.                         "Please call the Programmer for Assistance " _
  36.                         , vbCritical, "Warning Information"
  37.                 End If
  38.                  
  39.     rs.Close
  40.     Set rs = Nothing
  41.  
  42. End Sub
  43.  
  44. 'LOCK OBJECTS
  45. Sub objLock(x As Boolean)
  46. txtUserName.Enabled = Not x
  47. txtPassword.Enabled = Not x
  48. cmdOK.Enabled = Not x
  49. End Sub
  50.  
  51. Private Sub Image1_Click()
  52. End Sub
  53.  
  54. Private Sub Form_Load()
  55.  
  56. End Sub
what do you think is the problem? These codes are from the other project but it works fine but when I copied these codes and I checked 10000 times I always get Error 3709. Help me please. I'm gonna die....