If..And..Or.. ..And..Or..Then problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
You should create a table with two fields User_name and Password.

and then use just one DLookup, to check if the user exist and the password
is correct

Dim MyPassWord
MyPassWord = DLookUp("Password","Login Table","[User_name] = '" &
Forms!login1.login & "'"
If IsNull(MyPassWord) then
msgbox "User Does not exist"
Else
If MyPassWord <> Me![Password] Then
msgbox "Password incorect"
else
(the rest of the code)
end if
end if

When another user join in, all you need to do is add him/her to the table
 
Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if you
could use name as a variable, name = "Forms!login1.login" is going to put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
Lots of ways...
Try creating a table of Users and passwords, (Users must be unique) ,
and then do a Dlookup against that table to verify the Password.
Or a combobox with User in the first column and Password in the second
column (Hidden, Width=0) and check Password against the combo... ex.
cboLogin.Column(1)
(Combo columns are numbered 0, 1, 2, etc..)
 
I agree with Doug, I use a table store User ID and Password.but I take it
one step further by also storing the User's access level.
When the User enter their User ID and Password I validate the user Id and
password and display relevant error messages. Then if there is a valid user
and password the user has access to the relevant menu items depending on
their level of access.

--
Allan Murphy
Email: (e-mail address removed)
Douglas J Steele said:
Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if you
could use name as a variable, name = "Forms!login1.login" is going to put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or
name
=
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
Whatever table solution you use you can hide the table, just so it isn't
readily visible to users.
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
Hi,


Well, use a table, rather that data "in the code".


if 0 <> DCount(""*", "TableNameWithNameAndPasswords" , "name=
FORMS!FormName!name AND password=FORMS!FormName!Password") then

else

end if


basically, the DCount check for a matching record, if none is found, the
password is assumed illegal.


The data being in a table, you won't need to modify your code each time a
user wish to change his/her code.

Hoping it may help,
Vanderghast, Access MVP
 
So many tips. Thank you all.

Ofer:
In your suggestion, where does the ) go after DLookUP?

Dim MyPassWord
MyPassWord = DLookUp("Password","Login Table","[User_name] = '" &
Forms!login1.login & "'"
If IsNull(MyPassWord) then
msgbox "User Does not exist"
Else
If MyPassWord <> Me![Password] Then
msgbox "Password incorect"
else
(the rest of the code)
end if
end if

Thanks again.
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Ofer said:
You should create a table with two fields User_name and Password.

and then use just one DLookup, to check if the user exist and the password
is correct

Dim MyPassWord
MyPassWord = DLookUp("Password","Login Table","[User_name] = '" &
Forms!login1.login & "'"
If IsNull(MyPassWord) then
msgbox "User Does not exist"
Else
If MyPassWord <> Me![Password] Then
msgbox "Password incorect"
else
(the rest of the code)
end if
end if

When another user join in, all you need to do is add him/her to the table
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
In the end, try this
Dim MyPassWord
MyPassWord = DLookUp("Password","Login Table","[User_name] = '" &
Forms!login1.login & "'")
If IsNull(MyPassWord) then
msgbox "User Does not exist"
Else
If MyPassWord <> Me![Password] Then
msgbox "Password incorect"
else
(the rest of the code)
end if
end if

--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



jsc3489 said:
So many tips. Thank you all.

Ofer:
In your suggestion, where does the ) go after DLookUP?

Dim MyPassWord
MyPassWord = DLookUp("Password","Login Table","[User_name] = '" &
Forms!login1.login & "'"
If IsNull(MyPassWord) then
msgbox "User Does not exist"
Else
If MyPassWord <> Me![Password] Then
msgbox "Password incorect"
else
(the rest of the code)
end if
end if

Thanks again.
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Ofer said:
You should create a table with two fields User_name and Password.

and then use just one DLookup, to check if the user exist and the password
is correct

Dim MyPassWord
MyPassWord = DLookUp("Password","Login Table","[User_name] = '" &
Forms!login1.login & "'"
If IsNull(MyPassWord) then
msgbox "User Does not exist"
Else
If MyPassWord <> Me![Password] Then
msgbox "Password incorect"
else
(the rest of the code)
end if
end if

When another user join in, all you need to do is add him/her to the table
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
I keep getting "incorrect password"

here is my entire code for my 'form_password' as suggested:

Option Explicit
---------------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
---------------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
---------------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Password]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True

Dim Employee
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
---------------------------------------------------------------
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
---------------------------------------------------------------
and my 'Form_login1' code:

Option Compare Database
Option Explicit
---------------------------------
Private Sub Cancel_Click()
DoCmd.Close
End Sub
---------------------------------
Private Sub Submit_Click()

Dim stDocName As String

stDocName = "Password"
DoCmd.OpenForm stDocName

Exit_Submit_Click:
Exit Sub

Err_Submit_Click:
MsgBox err.Description
Resume Exit_Submit_Click

End Sub
---------------------------------------------------------------------

I'm also not sure how to build the "user" and "password" table for above as
suggested. I've only been working with Access for about two weeks. So I'm
very new at this.
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
On the form load you assign 1 to the gintPasswordFlag variable

On the after update event of the password, you have a select case for the
gintPasswordFlag
and if the case = 1, you display the MsgBox "Incorrect password", 16,
"Password"

You assign to it 1 and you never changing it, so it will display the message
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



jsc3489 said:
I keep getting "incorrect password"

here is my entire code for my 'form_password' as suggested:

Option Explicit
---------------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
---------------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
---------------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Password]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True

Dim Employee
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
---------------------------------------------------------------
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
---------------------------------------------------------------
and my 'Form_login1' code:

Option Compare Database
Option Explicit
---------------------------------
Private Sub Cancel_Click()
DoCmd.Close
End Sub
---------------------------------
Private Sub Submit_Click()

Dim stDocName As String

stDocName = "Password"
DoCmd.OpenForm stDocName

Exit_Submit_Click:
Exit Sub

Err_Submit_Click:
MsgBox err.Description
Resume Exit_Submit_Click

End Sub
---------------------------------------------------------------------

I'm also not sure how to build the "user" and "password" table for above as
suggested. I've only been working with Access for about two weeks. So I'm
very new at this.
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
If alter gintPasswordFlag I lose my three tries :(

Going home for the day, be back in the mornin'
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Ofer said:
On the form load you assign 1 to the gintPasswordFlag variable

On the after update event of the password, you have a select case for the
gintPasswordFlag
and if the case = 1, you display the MsgBox "Incorrect password", 16,
"Password"

You assign to it 1 and you never changing it, so it will display the message
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



jsc3489 said:
I keep getting "incorrect password"

here is my entire code for my 'form_password' as suggested:

Option Explicit
---------------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
---------------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
---------------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Password]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True

Dim Employee
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
---------------------------------------------------------------
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
---------------------------------------------------------------
and my 'Form_login1' code:

Option Compare Database
Option Explicit
---------------------------------
Private Sub Cancel_Click()
DoCmd.Close
End Sub
---------------------------------
Private Sub Submit_Click()

Dim stDocName As String

stDocName = "Password"
DoCmd.OpenForm stDocName

Exit_Submit_Click:
Exit Sub

Err_Submit_Click:
MsgBox err.Description
Resume Exit_Submit_Click

End Sub
---------------------------------------------------------------------

I'm also not sure how to build the "user" and "password" table for above as
suggested. I've only been working with Access for about two weeks. So I'm
very new at this.
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
I keep getting "Incorrect Password" because my table isn't built right. I
need detailed instruction to get this to work.

Table name: UserDef
I have two fields: User_Name and Pass
Where do I store the passwords? In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...

What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

Am I even close?
How frustrated can one person get?

Here is my current code for 'Form_Password':
-----------------------------
Option Explicit
-----------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
-----------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
-----------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Pass]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True
Dim Employee

Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
-----------------------------

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if you
could use name as a variable, name = "Forms!login1.login" is going to put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
The code look fine.
Did you fill the table with the data of user_name and password for each user
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



jsc3489 said:
I keep getting "Incorrect Password" because my table isn't built right. I
need detailed instruction to get this to work.

Table name: UserDef
I have two fields: User_Name and Pass
Where do I store the passwords? In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...

What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

Am I even close?
How frustrated can one person get?

Here is my current code for 'Form_Password':
-----------------------------
Option Explicit
-----------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
-----------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
-----------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Pass]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True
Dim Employee

Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
-----------------------------

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if you
could use name as a variable, name = "Forms!login1.login" is going to put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name =
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
So, where do I put the password data for each User?
Caption, default value, etc.?
Do I leave the 'Lookup' as 'Text Box'?

As I have mentioned before I am 2 weeks new to this? I am, however, somewhat
used to writing code. I'm an old BASIC writer from the 80's so VB makes some
sense to me, not alot, but some.
--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Ofer said:
The code look fine.
Did you fill the table with the data of user_name and password for each user
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck



jsc3489 said:
I keep getting "Incorrect Password" because my table isn't built right. I
need detailed instruction to get this to work.

Table name: UserDef
I have two fields: User_Name and Pass
Where do I store the passwords? In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...

What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

Am I even close?
How frustrated can one person get?

Here is my current code for 'Form_Password':
-----------------------------
Option Explicit
-----------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
-----------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
-----------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Pass]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True
Dim Employee

Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
-----------------------------

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if you
could use name as a variable, name = "Forms!login1.login" is going to put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus
causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or
name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or
name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name
=
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And
Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or
name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
The passwords get stored in the table.

The user name is typed into the textbox named Login on the form named
login1. The password is type into the textbox name Password on the current
form (do you have 2 separate forms involved, or just one?)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I keep getting "Incorrect Password" because my table isn't built right. I
need detailed instruction to get this to work.

Table name: UserDef
I have two fields: User_Name and Pass
Where do I store the passwords? In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...

What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

Am I even close?
How frustrated can one person get?

Here is my current code for 'Form_Password':
-----------------------------
Option Explicit
-----------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
-----------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
-----------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Pass]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True
Dim Employee

Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
-----------------------------

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if you
could use name as a variable, name = "Forms!login1.login" is going to put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey"
Or
name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor"
Or
name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or
name
=
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol"
Or
name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
Tables: TimeSheet - houses employee combobox, date, time, etc. fields
UserDef - employee fields

Forms: Calendar - used for dates in timesheet
Fail - failed password
Login1 - login screen
Password - self explanitory
Timesheet - user interface

I have Login1 with a dropdown menu to select name (with submit and cancel
buttons). Once submit is pressed, a password box comes up.

Now with all my trial and errors I've managed to get an "Error 2001: You
canceled the previous operation." when I try to enter a password whereas
before I was at least getting "Incorrect Password"
AAARRRGGGHHH!!!!!!(pulling out hair)

What is supposed to happen, once the correct password is enetered the
password box dissapears and my timesheet with the selected name comes up.

I'm about ready to say screw this and have my boss find an alternate method
for this!!!

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
The passwords get stored in the table.

The user name is typed into the textbox named Login on the form named
login1. The password is type into the textbox name Password on the current
form (do you have 2 separate forms involved, or just one?)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I keep getting "Incorrect Password" because my table isn't built right. I
need detailed instruction to get this to work.

Table name: UserDef
I have two fields: User_Name and Pass
Where do I store the passwords? In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...

What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

Am I even close?
How frustrated can one person get?

Here is my current code for 'Form_Password':
-----------------------------
Option Explicit
-----------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
-----------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
-----------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Pass]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True
Dim Employee

Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
-----------------------------

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if you
could use name as a variable, name = "Forms!login1.login" is going to put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus
causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey" Or
name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff" And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor" Or
name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or name
=
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And
Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett" And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol" Or
name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
The "Error 2001: You canceled the previous operation" message is often
indicative of the fact that you're mistyped something in the DLookup
statement. Make sure that the names of the fields and tables are all
correct.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
Tables: TimeSheet - houses employee combobox, date, time, etc. fields
UserDef - employee fields

Forms: Calendar - used for dates in timesheet
Fail - failed password
Login1 - login screen
Password - self explanitory
Timesheet - user interface

I have Login1 with a dropdown menu to select name (with submit and cancel
buttons). Once submit is pressed, a password box comes up.

Now with all my trial and errors I've managed to get an "Error 2001: You
canceled the previous operation." when I try to enter a password whereas
before I was at least getting "Incorrect Password"
AAARRRGGGHHH!!!!!!(pulling out hair)

What is supposed to happen, once the correct password is enetered the
password box dissapears and my timesheet with the selected name comes up.

I'm about ready to say screw this and have my boss find an alternate method
for this!!!

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
The passwords get stored in the table.

The user name is typed into the textbox named Login on the form named
login1. The password is type into the textbox name Password on the current
form (do you have 2 separate forms involved, or just one?)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
I keep getting "Incorrect Password" because my table isn't built right. I
need detailed instruction to get this to work.

Table name: UserDef
I have two fields: User_Name and Pass
Where do I store the passwords? In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...

What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

Am I even close?
How frustrated can one person get?

Here is my current code for 'Form_Password':
-----------------------------
Option Explicit
-----------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
-----------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
-----------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Pass]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True
Dim Employee

Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
-----------------------------

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


:

Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even
if
you
could use name as a variable, name = "Forms!login1.login" is going
to
put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName & "'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case,
not
just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying compare multiple Or statements to match names with passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus
causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] =
"rey"
Or
name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name =
"Eckhoff"
And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] =
"cor"
Or
name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh"
Or
name
=
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And
Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name =
"Bennett"
And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] =
"hol"
Or
name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
Well, I haven't changed anything, this is what I have:

If StrComp(Nz(DLookup("[Password]", "Userdef", "User_Name ='" & strName &
"'"),""), strPassword, 0) = 0 Then

and this worked just fine for a while.

And where EXACTLY do I put my list of passwords in my UserDef table?
In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...
What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
The "Error 2001: You canceled the previous operation" message is often
indicative of the fact that you're mistyped something in the DLookup
statement. Make sure that the names of the fields and tables are all
correct.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


jsc3489 said:
Tables: TimeSheet - houses employee combobox, date, time, etc. fields
UserDef - employee fields

Forms: Calendar - used for dates in timesheet
Fail - failed password
Login1 - login screen
Password - self explanitory
Timesheet - user interface

I have Login1 with a dropdown menu to select name (with submit and cancel
buttons). Once submit is pressed, a password box comes up.

Now with all my trial and errors I've managed to get an "Error 2001: You
canceled the previous operation." when I try to enter a password whereas
before I was at least getting "Incorrect Password"
AAARRRGGGHHH!!!!!!(pulling out hair)

What is supposed to happen, once the correct password is enetered the
password box dissapears and my timesheet with the selected name comes up.

I'm about ready to say screw this and have my boss find an alternate method
for this!!!

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


Douglas J Steele said:
The passwords get stored in the table.

The user name is typed into the textbox named Login on the form named
login1. The password is type into the textbox name Password on the current
form (do you have 2 separate forms involved, or just one?)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I keep getting "Incorrect Password" because my table isn't built right. I
need detailed instruction to get this to work.

Table name: UserDef
I have two fields: User_Name and Pass
Where do I store the passwords? In 'Row Source'?
What format? "pass1";"pass2"... or pass1;pass2...

What 'Display Control' do I use?
What 'Row Source Type'?
Or does it just need to be a 'Text Box'"?

Am I even close?
How frustrated can one person get?

Here is my current code for 'Form_Password':
-----------------------------
Option Explicit
-----------------------------
Private Sub Form_Load()

gOkToClose = False
' number of tries
gintPasswordFlag = 1

End Sub
-----------------------------
Private Sub Form_Unload(Cancel As Integer)

If Not gOkToClose Then
Cancel = True
End If

End Sub
-----------------------------
Private Sub PASSWORD_AfterUpdate()
On Error GoTo err_PASSWORD_AfterUpdate

Dim strName As String
Dim strPassword As String

strName = Forms!login1.Login
strPassword = Me![Password]

If StrComp(Nz(DLookup("[Pass]", "UserDef", "User_Name ='" & strName &
"'"), ""), strPassword, 0) = 0 Then

gOkToClose = True
Dim Employee

Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
DoCmd.Close A_FORM, "Password"
Else
' three tries
Select Case gintPasswordFlag
Case 1 To 2
DoCmd.Beep
MsgBox "Incorrect password", 16, "Password"
gintPasswordFlag = gintPasswordFlag + 1
Case Else
DoCmd.Beep
DoCmd.OpenForm "Fail"
End Select
End If
exit_PASSWORD_AfterUpdate:
Exit Sub

err_PASSWORD_AfterUpdate:
MsgBox "Error " & err & ": " & Error$, 0, "Password"
Resume exit_PASSWORD_AfterUpdate

End Sub
-----------------------------

--
I reject your reality and substitute my own.

Promote hydrogen - one of the best "clean" fuels there are!


:

Before addressing your actual question, let me point out that name is a
reserved word, and shouldn't be used for your own purposes. And even if
you
could use name as a variable, name = "Forms!login1.login" is going to
put
the literal string "Forms!login1.login" into the variable.

What you really want is:

Dim strName As String

strName = Forms!login1.login

However, that isn't the best approach: better would be to store the
names
and passwords in a table, and look up to see whether you've got a match.

Dim strName As String
Dim strPassword As String

strName = Forms!login1.login
strPassword = Me![Password]

If Nz(DLookup("[Password]", "MyTable", "UserName ='" & strName &
"'"),
"") = strPassword Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee

If you want to ensure that the password keyed in matches in case, not
just
value, use

If StrComp(Nz(DLookup("[Password]", "MyTable", "UserName ='" &
strName &
"'"),""), strPassword, 0) = 0 Then

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm trying compare multiple Or statements to match names with
passwords.

The statement really needs to be:

If Forms!login1.login = "Davis" And Me![Password] = "dav" or
Forms!login1.login ...

but, this will wind up being too long and it will "word wrap", thus
causing
errors.

High security isn't needed so I came up with this with help from these
boards:)

Is there a way to simplify the following:
-----------------------------------------------
Dim name As String

name = "Forms!login1.login"

If name = "Davis" And Me![Password] = "dav" Or name = "Neal" And
Me![Password] = "nea" Or name = "Reynolds" And Me![Password] = "rey"
Or
name
= "Lyons" And Me![Password] = "lyo" Or name = "Lauth" And
Me![Password] =
"lau" Or name = "Bonds" And Me![Password] = "bon" Or name = "Eckhoff"
And
Me![Password] = "eck" Or name = "Corrigan" And Me![Password] = "cor"
Or
name
= "Setterlund" And Me![Password] = "set" Or name = "Jimenez" And
Me![Password] = "jim" Or name = "Dehart" And Me![Password] = "deh" Or
name
=
"Cowsert" And Me![Password] = "cow" Or name = "McClellan" And
Me![Password] =
"mcc" Or name = "Scott" And Me![Password] = "sco" Or name = "Bennett"
And
Me![Password] = "ben" Or name = "Holzhauer" And Me![Password] = "hol"
Or
name
= "Merlino" And Me![Password] = "mer" Or name = "Harrington" And
Me![Password] = "har" Then

gOkToClose = True
Dim Employee As String
Employee = Forms!login1.[Login]
DoCmd.Close acForm, "Login1"
DoCmd.OpenForm "Timesheet", acNormal, "", "", acAdd, acNormal
Forms!timesheet.SetFocus
Forms!timesheet.Employee = Employee
 
Ofer said:
The code look fine.
Did you fill the table with the data of user_name and password for each user
--

Could you be more specific on where to put the data for each above.
I've tried quite a few things but I keep getting "Incorrect Password"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top