Password Code

dnrhymer4

Registered User.
Local time
Today, 03:44
Joined
Mar 1, 2010
Messages
12
Hi,

I'm trying to require a password using an input box in order to enter a form. I have a table listing the managers and passwords. I've pieced together some code. The problem is that it will only open for one manager. Any help is greatly appreciated.

Private Sub CmdOpen_FY_09_10_Forecast_Form_Click()
Dim Getpass As String
If IsNull(Me.cboManager) Or Me.cboManager = "" Then
MsgBox "You must select a Manager.", vbOKOnly
Cancel = True
Me.cboManager.SetFocus
ElseIf (Me.cboManager) & "" <> "" Then
Getpass = InputBox("Enter Password", "Please Enter Your Password")
If Getpass = DLookup("[Password]", "Managers", "Manager = '" & Me.cboManager & "'") Then
DoCmd.RunMacro "mcrOpen FY 09-10 Forecast", 1
Else 'password is incorrect
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "You are not allowed access.", vbCritical, "Invalid Password"
End If
End If
End Sub
 
Why not use a form for collecting both pieces of information at once? It would even look more professional and easier to manage.

Also, investigate the DLookup() function. It would come in handy.
 
There are reports that are also filtered by the cboManager that everyone has access to. I'm only trying to limit access to the data entry.
 
Oops... apologies, didn't see you had used the DLookup :)

So what is it not doing? And what does your macro do?
 
It's only finding the password for one manager. The macro opens another form while applying a filter.
 
That's what a DLookup essentially does. Isn't it supposed to find the password for the selected manager?
 
Yep, but I have no idea why it's only working for one manager. If I select any other manager and enter the password, it tells me the the password is incorrect.
 
1. You don't need to set focus on cboManager to get the values.

2. Add a

Debug.Print Me.cboManager

into the start of the code to see what value it is actually returning.

to the code just after this line:
 
Is cboManager a unique ID for each Manager?

Try putting message boxes to see what the result is for both the username and password.
 
Figured it out. My DLookup was looking at the wrong field. Thanks for the help!
 

Users who are viewing this thread

Back
Top Bottom