|
-
Dec 4th, 2007, 09:22 AM
#1
Thread Starter
Hyperactive Member
Database Login
I am creating a login routine that will check the username and password in table. I have managed to get it to work. The problem is i have used the .Find method to find the Username, if the username exists in the database and the password is the same in the record it will login, however, if the username is incorrect then and error message is generated (See below). Is there a more efficient way to create a login routine for this database via VB? Otherwise, how would i check to see if the username is actually in the database?
Error
Run-time error '3021':
Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record.
Code:
Private Sub Command1_Click()
With adoRecordSet
If .EOF Or .BOF Then
.MoveFirst
.MoveNext
Else
' What if the Username is incorrect?
.Find "Username = '" & Text1.Text & "'", , adSearchForward
If Text2.Text = .Fields("Password") Then
strUsername = Text1.Text
Form2.Show
Unload Me
Else
MsgBox "The Username and / or Password is incorrect. Please" & vbCrLf _
& "try again.", vbExclamation, "Login Error"
End If
End If
End With
End Sub
Regards,
Jenova
-
Dec 4th, 2007, 09:35 AM
#2
Re: Database Login
If Not .EOF or .BOF is one way.
Error trapping the 3021 error is another.
-
Dec 5th, 2007, 05:08 AM
#3
Re: Database Login
Code:
'Assume ADO connection object already setup
Dim rs As ADODB.Recordset
Set rs = cn.Execute ("SELECT COUNT(*) AS ret_cnt FROM tblUsers WHERE UserName = '" & Text1.Text & "' AND Password = '" & Text2.Text & "' ")
If rs.Fields("ret_cnt").Value = 1 Then
Form2.Show
Else
MsgBox "The Username and / or Password is incorrect. Please" & vbCrLf _
& "try again.", vbExclamation, "Login Error"
End If
rs.Close
Set rs = Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|