Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP! VB Code for password 1

Status
Not open for further replies.

dnrhymer4

Technical User
Mar 1, 2010
6
US
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
 
put this in here and read what you get.

Getpass = InputBox("Enter Password", "Please Enter Your Password")

debug.print "Input: " & getPass
debug.print "Search: " & nz(DLookup("[Password]", "Managers", "Manager = '" & Me.cboManager & "'"))

If Getpass = DLookup("[Password]", "Managers", "Manager = '" & Me.cboManager & "'") Then

I recommend a NZ around your dlookup to avoid an error on a null result.
 
Thanks for the reply. But I'm still having the same problem. I only get results for one manager
 
I was hoping you would tell me what the results of the debug.print show.

I assume it shows that
Getpass <> DLookup("[Password]", "Managers", "Manager = '" & Me.cboManager & "'")

Please post the results in the case where it does not run.
 
Sorry, I'm a beginner with this. I don't know if this is correct or not, but in the Immediate window, it shows this:

Input: 7100
Search:
 
Thanks.
So that tells me that your dlookup is not returning a value.

Which means either the dlookup is not written correct, or the value coming from cboManager is not correct and thus does not find a manager.

add one more debug
debug.print "Manager " & Me.cboManager
and repost.
 
Ok, here's the next debug

Input: 7100
Manager Bach
Search:

 
DLookup("[Password]", "Managers", "Manager = '" & Me.cboManager & "'")

So my guesses
1) Bach is not in the Managers table or does not have a password.
2) Your field is not called "Manager", but something like "ManagerName"

You could test this in the immediate window
?DLookup("[Password]", "Managers", "Manager = 'Bach'")

This should return the password for Bach if everything is correct.
 
Ahh, that was it. I put the Table name instead of the field name. Thanks so much. But now I'm getting a syntax error with the DLookup?

If Getpass = DLookup("[Password]", "Managers", "Last Name = '" & Me.cboManager & "'") Then
 
I figured it out. [Last Name] Thanks so much for your help! Just overlooking the little thing. Another set of eyes is always a great help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top