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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Form for Multiple Objects HELP! 1

Status
Not open for further replies.

DarkOne72

Technical User
Jun 14, 2002
208
US
Hello All --
I need some assistance if possible. I am needing help with a password form I have. I have a table named PasswordTable with a single password in it and a password form named AdminForm. On the form I have an unbound text box named PasswordTextBox , a close button and a Submit button. I can get the code to work when I just want to open 1 form by using the following code:
Code:
Private Sub Submit_Click()
If DLookup("AdminPassword", "PasswordTable") = Me.PasswordTextBox Then
  DoCmd.Close
  DoCmd.OpenForm "Form_to_Open", acNormal
Else
  MsgBox "Incorrect Password! Try again!"
  PasswordTextBox.SetFocus
  Me.PasswordTextBox = ""
End If
End Sub

What I need to happen is be able to call the password form up from multiple buttons on click and open up that form based on the button that was clicked. For instance; If I click view report button it opens the password form and if password is successfully entered then it closes the password form then opens the report. If I click on a different button that would open a different form it too will call the password form and if the password i s successfully entered it would close the password form and then open up what was intended. In any even if the user closes or cancels the password form without putting in the correct password it will not open up anything that was clicked initially.

I am not sure how to go about this if someone could please assist me.

Thanks!
 
You need to swap a couple lines so you don't close the form before attempting to get the OpenArgs

Code:
Private Sub Submit_Click()
If Me.OpenArgs & "" <> "" Then
  If DLookup("AdminPassword", "PasswordTable") = Me.PasswordTextBox Then
    DoCmd.OpenForm Me.OpenArgs, acNormal
    DoCmd.Close acForm, Me.Name
   Else
    MsgBox "Incorrect Password! Try again!"
    PasswordTextBox.SetFocus
    Me.PasswordTextBox = ""
  End If
End If
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Awesome!! That works, but one question... How do I get it to show the form or report that it opens instead of having to go up top and click it?
To be clear here's what it does: I click the button from the menu and a popup form opens asking for the password; I type in the correct password and the password form disappears and the requested form opens on another tab up top but doesn't display unless I click on it; it is still showing the menu .


Thank you by the way !!!
 
I couldn't get the setfocus to work properly anywhere once it tried to load the form after the password was entered. So what I did instead was on the forms that have a password I put the Modal to YES and it seems to work just fine for what i need it too. I want to thank everybody for all the ideas and suggestion; especially dhookom ! I love the code you came up and will be putting it in my library [bigsmile] . You have all been a great help and I learned a few new tricks.

Thanks !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top