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:
==============================================
frmLogin codes:
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....
- Option Explicit
- Public conn As ADODB.Connection
- Public Sub connect()
- Set conn = New ADODB.Connection
- conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\database.mdb;Persist Security Info=False"
- End Sub
- Sub Main()
- connect
- frmLogin.Show
- End Sub
- Dim ctr As Byte
- Private Sub cmdCancel_Click()
- End
- End Sub
- Private Sub cmdOK_Click()
- Dim rs As New ADODB.Recordset
- rs.Open "SELECT * FROM users WHERE username = '" & LCase(txtUserName.Text) & "'", conn, adOpenStatic, adLockReadOnly
- If rs.RecordCount <> 0 Then
- If LCase(txtPassword.Text) = rs!password Then
- MsgBox "Username and Password Succesful!"
- Else
- MsgBox "Invalid Password, Try again!", vbCritical, "Warning"
- txtUserName.Text = ""
- txtPassword.Text = ""
- txtUserName.SetFocus
- ctr = ctr + 1
- End If
- Else
- MsgBox "Invalid Login, Try again!", vbCritical, "Warning"
- txtUserName.Text = ""
- txtPassword.Text = ""
- txtUserName.SetFocus
- ctr = ctr + 1
- End If
- If ctr = 3 Then
- objLock (True)
- MsgBox "You have attempted to Login 3 Times in the system. " & _
- "Please call the Programmer for Assistance " _
- , vbCritical, "Warning Information"
- End If
- rs.Close
- Set rs = Nothing
- End Sub
- 'LOCK OBJECTS
- Sub objLock(x As Boolean)
- txtUserName.Enabled = Not x
- txtPassword.Enabled = Not x
- cmdOK.Enabled = Not x
- End Sub
- Private Sub Image1_Click()
- End Sub
- Private Sub Form_Load()
- End Sub
- 207 views