How prevent user from openein a form from a main menu if the form they are trying to open has a tag of "Secure"

I have a main menu form.  On that main menu form are several command buttons that have a tag of "Secure".  If the user clicks on one of the buttons that is set to open a "Secure" form, I want a password form to open and have the user enter a password.  If the password equals DLookup("[dbPassword]", "tblSetup") then let them proceed.  

If the password they enter does not equal the DLookup, present a message form and Do NOT let them in.

How can I do this from the onclick event of the form?  Or if it can't be done this way, how?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
Something like this should get you started

Private Sub Form_Open(Cancel As Integer)
Dim strPword As String
strPword = InputBox("Enter Password")
If strPword <> DLookup("[dbPassword]", "tblSetup") Then
    MsgBox "Access Denied"
    Cancel = True
End If
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
Note that in your "one record password table", need to have a rock-solid way to prevent more that one record from ever being entered.

But this can get complicated depending on what you need, this might be better dealt with in a separate, new question.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What's the point of using the Tag property of the control? If you want to ask the user to enter a password to open a form, use Jeff's suggestion, or do the same thing in the OnClick event of any button where a password is needed. Same concepts apply, but instead of running Jeff's code in the Open event of a Form, you run it in the Click event of the button.
SteveL13Author Commented:
Very simple and straight forward.  Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.