Password help

mshell

mshell
Local time
Today, 14:47
Joined
Jul 15, 2004
Messages
6
I am attempting to set up password protection to fields in a form. I need for the form to display an error message if the signature does not match any of the defined names. This is my code. It seems to be completely bypassing the code that tells it to what to do if the name is not in the defined names list. Please help!!!


Private Sub Supplier_Signature_BeforeUpdate(Cancel As Integer)
Dim update As Variant
Dim password As Variant
If [Supplier Signature] = "XXX" Then
update = InputBox("Enter Password", password)
End If
If [Supplier Signature] = "XXX" And update <> "1280" Then
MsgBox ("Please enter the correct password")
DoCmd.CancelEvent
If [Supplier Signature] <> "ABC" Or "DEF" Or "GHI" Or "JKL" Or "MNO" Or "PQR" Or "STU" Or "VWX" Or "YZA" Or "BCD" Or "EFG" Or "HIJ" Or "KLM" Or "NOP" Or "QRS" Or "TUV" Or "WXY" Or "ZAB" Or "CDE" Or "FGH" Or "IJK" Or "LMN" Or "OPQ" Or "RST" Or "UVW" Or "XYZ" Or "ACB" Or "DFG" Or "JKM" Then
MsgBox ("Either you are not authorized to complete this form or you have entered an invalid name. Please try again")
DoCmd.CancelEvent
Else
If [Supplier Signature] = "MNA" Then
update = InputBox("Enter Password", password)
End If
 
Last edited:
If [Supplier Signature] = "Sharon DEmidio" And update <> "1280" Then
MsgBox ("Please enter the correct password")
DoCmd.CancelEvent
If [Supplier Signature] <> "Pruitt Wilder" Or "Daniel Hadley" Or "Bennie Chapman" Or "Sharon DEmidio" Or "Billy Hammock" Or "Melinda Evans" Or "Tony Johnson" Or "Mitch

Are you perhaps missing an END IF just after the DoCmd.CancelEvent? I counted more IFs than END IFs.
 
This

If [Supplier Signature] <> "Pruitt Wilder" Or "Daniel Hadley" Or "Bennie Chapman"

would have to be this (note structure difference):

If [Supplier Signature] <> "Pruitt Wilder" Or [Supplier Signature] <> "Daniel Hadley" Or [Supplier Signature] <> "Bennie Chapman"...

plus your OR's need to be AND's
 
If [Supplier Signature] <> "Pruitt Wilder" Or "Daniel Hadley" Or "Bennie Chapman" Or "Sharon DEmidio" Or "Billy Hammock" Or "Melinda Evans" Or "Tony Johnson" Or "Mitch Yates" Or "Lisa Harrison" Or "Janice Smith" Or "Terry Helms" Or "Jason Wainwright" Or "Eddie Peterson" Or "Janet Cumbie" Or "Ralph Barfield" Or "Lori McDaniel" Or "Cherice Thomka" Or "Chris Mulvey" Or "Vance Brooks" Or "Perry Searcy" Or "Mitch Garner" Or "Russ Mullins" Or "Myra Boyt" Or "Pam Jenkins" Or "Michelle Brooks" Or "Rolfe Henry" Or "William Carlisle" Or "David Busha" Or "Mike Lenhart" Then


This is only part of the code. The end if's are further down. The problem appears to be with the OR statements. The passwords work fine but I am allowed to enter a name that is not defined with out being prompted for a password and I do not want anyone to be able to complete the field unless they are in the list.
 
That helped. Thanks!!! Now I have a really dumb question. How do I tell visual basic that the code continues on the next line? :o
 
I assume you mean to break up a long line. A space and then an underscore, like:
Code:
    If bytVersion >= conMinAccessVersion _
     And bytVersion <= conMaxAccessVersion Then
 
By the way, you have so many options in the user list, I would say you should be saving them in a table and looking there to validate your user (passwords too). The way it is, you have to change code each time a user leaves or you get a new one. Not very flexible. Using a table would reduce this to something like 10 lines of code, and it would never have to be changed for adds/edits/deletions to your users/passwords.
 
Thanks for your help. I have finished the code (it works) and there is a lot of it (17 pages). How would I achieve the same results by using a table?
 
And worse than there being a lot of code is the fact that you have to change it any time anything changes with users. You should never have to change code in that situation. With a simple table containing user and password fields, this will test for a valid user name being entered:

If IsNull(DLookup("[UserName]", "tblUsers", "[UserName]='" & Me.txtUserID & "'")) Then
'bad name

and this will test the password:

If DLookup("[UserPassword]", "tblUsers", "[UserName]='" & Me.txtUserID & "'") <> Me.txtPW Then
'bad password

I think there's a more comprehensive (more features) sample in the Sample Databases forum here, though I haven't looked at it.
 
Thanks for all of your help. I will experiment with the table next week in test database. Right now, I am just happy to have the forms working properly. :)
 

Users who are viewing this thread

Back
Top Bottom