using query to find a record

romio

Registered User.
Local time
Today, 04:38
Joined
Apr 20, 2005
Messages
68
The strSql string should find the record that I have already saved in my admin table and then compare it with combusername, where is my mistake.

Code:
Private Sub Command7_Click()


'Dim db As Database
Dim strSql As String
'Set db = CurrentDb()


strSql = "Select adminpass From admin"


If ((Nz(txtpassword, "") = "") Or (Nz(combusername, "") = "")) Then

MsgBox "Please Enter A Valid Access", vbOKOnly, "Error"

ElseIf (txtpassword = "admin" And combusername = strSql) Then

DoCmd.Close acForm, "Secure"
DoCmd.OpenForm "Home"
 

ElseIf (txtpassword = "user" And combusername = "user") Then

DoCmd.Close acForm, "Secure"
DoCmd.OpenForm "Home"

Else

MsgBox "Wrong Password, Please Try Again", vbOKOnly, "Error"
combusername = ""
txtpassword = ""
combusername.SetFocus


End If

End Sub
 
try something like this

Code:
Private Sub Command7_Click()
Dim strSql As String
Dim rs As DAO.Recordset

strSql = "Select adminpass From admin"
Set rs = CurrentDb.OpenRecordset(strSql, dbOpenForwardOnly)
rs.MoveFirst

If ((Nz(txtpassword, "") = "") Or (Nz(combusername, "") = "")) Then

MsgBox "Please Enter A Valid Access", vbOKOnly, "Error"

ElseIf (txtpassword = "admin" And combusername = rs!adminpass) Then

DoCmd.Close acForm, "Secure"
DoCmd.OpenForm "Home"
 

ElseIf (txtpassword = "user" And combusername = "user") Then

DoCmd.Close acForm, "Secure"
DoCmd.OpenForm "Home"

Else

MsgBox "Wrong Password, Please Try Again", vbOKOnly, "Error"
combusername = ""
txtpassword = ""
combusername.SetFocus


End If

But make sure you do some searches on Security in these forums! there are a lot of threads on it and the pitfalls in making your own!

peter
 
this is what I got:

invalid operation

Code:
rs.MoveFirst
 

Users who are viewing this thread

Back
Top Bottom