View Full Version : One question


atisz
05-18-2005, 02:54 AM
Hi,

I have cboUser for choosing username, txtpassword for password input and this code, wich verify if the password is correct for selected user:

'Check value of password in tblUsers to see if this matches value chosen in combo box

If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) Then

lngMyEmpID = Me.cboUser.Value
'Things to do....


My question is: can this code be modify to verify also, if the user is an admin user or a simple user (I have this contained in tblUser's table UserType field), and if it is User open Form1, if it is Admin open Form2?
Any help apreciated.

Attila

KenHigg
05-18-2005, 03:33 AM
If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) Then
If DLookup("UserType", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) = "Admin" Then
Do some admin stuff
Else
Do some other stuff
End if
End if


???

atisz
05-18-2005, 05:28 AM
If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) Then
If DLookup("UserType", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) = "Admin" Then
Do some admin stuff
Else
Do some other stuff
End if
End if


???

Thank you!
It's great! :)))
But this drive me, somehow, in another problem. On the else I had a messagebox , in case the password wasn't right.
Now I modified the code this way:

If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) Then
If DLookup("UserType", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) = "Admin" Then
Do some admin stuff
Else
If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) Then
If DLookup("UserType", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) = "User" Then
Do some other stuff
Else
'MsgBox "Error message"
End if
End if
End if

but if the password is wrong both case, it didn't pop up the Msgbox.
What could be wrong?

Thankx
Attila

KenHigg
05-18-2005, 05:39 AM
Did you mean to leave the comma in before the msgbox command?

atisz
05-18-2005, 09:49 PM
Did you mean to leave the comma in before the msgbox command?

No, I didn't left the comma.
That way of course it can't work. I used the code without the comma.

Attila

KenHigg
05-19-2005, 03:26 AM
Did you get this working? If not, cut and paste the code to a post. :)

skea
05-19-2005, 03:39 AM
Try This

If Me.txtpassword.Value = DLookup("Password", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) Then
If DLookup("UserType", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) = "Admin" Then
Do some admin stuff
ElseIf DLookup("UserType", "tblUsers", "[lngEmpID]=" & Me.cboUser.Value) = "User" Then
Do some other stuff
Else
'MsgBox "Error message"
Exit sub
End if

atisz
05-20-2005, 12:34 AM
Thank you, guys!

Thanked to you now my form is working the way I want.

Attila