Comparing passwords

benc

Registered User.
Local time
Today, 04:01
Joined
Dec 31, 2001
Messages
57
i have created a login window by using a form. And using Dlookups.

The username works fine however when i enter the password i get a type mismatch error. Here is my code so far.

Private Sub open_form_Click()
Dim Staff As String
Dim admin As String
Dim Group As Variant
Dim getpass As Variant


Staff = "Staff"
admin = "admin"


Group = DLookup("[Group]", "usernames", "[Username] = " & "'" & Me.Username & "'")
getpass = DLookup("[password]", "usernames", "[Username] = " & "'" & Me.Username & "'")

If Me.password Is Not getpass Then
MsgBox "Your password is incorrect. Access Denied"
End If

If Group = Staff Then

Dim userform As String
Dim stLinkCriteria1 As String

userform = "User Form"
DoCmd.openform userform, , , stLinkCriteria1

ElseIf Group = admin Then

Dim openform As String
Dim stLinkCriteria2 As String

openform = "Admin Form"
DoCmd.openform openform, , , stLinkCriteria2

End If

End Sub

Also after the access denied message has been displayed i would also like to set the password field on the form to blank and then to stop before going onto to load the seperate forms. I have only been writing code for a few weeks... am i going about it in the right way?

If anyone could help i would be most grateful.

Many Thanks
 
I would change the line:

If Me.password Is Not getpass Then
MsgBox "Your password is incorrect. Access Denied"
End If

to

If Me.password <> getpass Then
MsgBox "Your password is incorrect. Access Denied"
Me.password = ""
me.password.setfocus
Exit Sub
End If


The Is operator is used to confirm if two object references refer to the same object (from Microsoft Help). It doesn't check to see if the values match. The above changes should also clear the password field, move the cursor back to that field and cancel the rest of the program.

HTH
SteveA
smile.gif
 

Users who are viewing this thread

Back
Top Bottom