whats going wrong? (1 Viewer)

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
Password Form

I have the following code

Code:
Private Sub cmdOK_Click() 
'On Error GoTo Err_cmdOK_Click 

If IsNull(Me.TxtName) Or Me.TxtName = "" Then 
    MsgBox "You must enter a User Name.", vbCritical, "User Name Required" 
    Me.TxtName.SetFocus 
    Exit Sub 
End If 
    
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then 
    MsgBox "You must enter a valid password.", vbCritical, "Enter a valid password." 
    Me.txtPassword.SetFocus 
    Exit Sub 
End If 

If Me.txtPassword.Value = DLookup("strpassword", "TblUsers", "[password] =" & Me.txtPassword.Value) Then 
   Password = Me.txtPassword.Value 
    DoCmd.Close acForm, "FrmPassword", acSaveNo 
    DoCmd.OpenForm "frmadminarea" 
Else 
    MsgBox "Password Invalid, Please try again.", vbCritical, "Invalid Password Entered" 
    Me.txtPassword.SetFocus 
End If 

intlogonattempts = intlogonattempts + 1 
If logonattempts > 3 Then 
    MsgBox "You have entered the wrong password 3 times, Please contact your administrator.", vbCritical, "Access denied!!" 
    Application.Quit 
End If 
Exit sub

but there seems to be something wrong
The debugger points to the "Password = Me.txtPassword.Value" section, but i don't know why
Please help
 
Last edited by a moderator:

WayneRyan

AWF VIP
Local time
Today, 15:48
Joined
Nov 19, 2002
Messages
7,122
moose,

Just a guess here ...

Code:
Dim Pasword As String
Password = Nz(DLookup("[Password]", "TblUsers", "[password] = '" & Me.txtPassword & "'", "")
If Me.txtPassword = Password Then 
   DoCmd.Close acForm, "FrmPassword"
   DoCmd.OpenForm "frmadminarea" 
Else 
    MsgBox "Password Invalid, Please try again.", vbCritical, "Invalid Password Entered" 
    Me.txtPassword.SetFocus 
End If

The Nz function will make sure that (if not found), the Password is
not Null.

I changed the table's field to [Password], I don't think it was strPassWord.

Wayne
 

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
i just get a syntax error now
 

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
I put an extra ) at the end and now get the attached screen
 

Attachments

  • Error.png
    Error.png
    30.8 KB · Views: 96

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
Below is the full list of my code, can anyone see where it is falling over please

TblUser has the fields ScreenName, Password and the 2 fields on my FrmPassword are TxtName and TxtPassword. I want TxtName to verify the name entered by looking up the screenName field and TxtPassword to lookup the password field.

The code below falls over at the Password = Nz(DLookup point saying Wrong number of arguments or invalid property assignment

PLEASE PLEASE PLEASE HELP

Private Sub cmdOK_Click()
Dim Password As String
Dim intlogonattempts As String

If IsNull(Me.TxtName) Or Me.TxtName = "" Then
MsgBox "You must enter a User Name.", vbCritical, "User Name Required"
Me.TxtName.SetFocus
Exit Sub
End If

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a valid password.", vbCritical, "Enter a valid password."
Me.txtPassword.SetFocus
Exit Sub
End If

Password = Nz(DLookup("[Password]", "TblUsers", "[password] = '" & Me.txtPassword & "'", ""))

If Me.txtPassword = Password Then
DoCmd.Close acForm, "FrmPassword"
DoCmd.OpenForm "frmadminarea"
Else
MsgBox "Password Invalid, Please try again.", vbCritical, "Invalid Password Entered"
Me.txtPassword.SetFocus
End If

intlogonattempts = intlogonattempts + 1
If intlogonattempts > 3 Then
MsgBox "You have entered the wrong password 3 times, Please contact your administrator.", vbCritical, "Access denied!!"
Application.Quit
End If


If Me.txtPassword = "administrator" Then

DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "FrmAdminArea"

Else

MsgBox "Password Incorrect. Please try again", vbCritical, " Incorrect Password Entered"
Me.txtPassword = ""
Me.TxtName = ""
Me.TxtName.SetFocus
End If

Exit_cmdOK_Click:
Exit Sub

End Sub
 
R

Rich

Guest
Password = Nz(DLookup("[Password]", "TblUsers", "[password] = '" & Me.txtPassword & "'", ""))


Try
Password = Nz(DLookup("[Password]", "TblUsers",( "[password] = ' " & Me.txtPassword & " ' ) ") )
 

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
still comes up with Syntax error
 
R

Rich

Guest
scrap Password and try If Me.txtPassword = Nz(DLookup("[Password]", "TblUsers",( "[password] = ' " & Me.txtPassword & " ' ) ") )


or try changing
Dim Password As String
to
Dim Password As Variant
 

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
Tried both suggestions and still getting a Syntax Error
 
R

Rich

Guest
password = Nz(DLookup("[Password]", "TblUsers", "([password] = '" & Me.txtPassword & "')"))
 

pdx_man

Just trying to help
Local time
Today, 07:48
Joined
Jan 23, 2001
Messages
1,347
Well, I'll toss my 2 cents in to add to the confusion ;)

Please confirm the datatype in the TblUsers table for this field.

Also, Password is a reserved word, and it may be having issues with that. Try UserPassword instead.
 
Last edited:

pdx_man

Just trying to help
Local time
Today, 07:48
Joined
Jan 23, 2001
Messages
1,347
Have you tried:

Password = Nz(DLookup("[Password]", "TblUsers", "[password] = '" & Me.txtPassword & "'"), "")

You have to close your DLookup function before letting the Nz have a go.
 

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
Thanks Rich, your last solution worked fine with only one exception,
Although the form now checks for a valid password (working fine), it still lets you in no matter what user name you enter
Any ideas please
 
R

Rich

Guest
You need two conditions, you have to check that the user name matches the password

password = Nz(DLookup("Password", "tblUsers", "([Password] = '" & Me![txtPassword] & "') And ([UserName] = '" & Me![TXTName] & "')"))
 

moose

c'mon Chelsea
Local time
Today, 15:48
Joined
May 18, 2001
Messages
139
Thanks Rich, I just worked that out as you posted
Thanks for all your help :)
 

Users who are viewing this thread

Top Bottom