put a password on a form

H

Herc

I need to put a password on a button in a form. Here is what I have done. On
the form, I have the button open another form I called password. On the
password form, I have put in a text field I called password. On the
properties of the text field that is called password I went to the data tab
and set the input mask to "Password". On the Event tab, in the "After Update"
field, I clicked on the "..." to go into the code builder. I put the below
code in and it does not seem to care if I put anything in there. It just will
NOT open up the form called "Admin Form". I know I must be missing something
somewhere. From what I read, this should work. Also, could you give me a hint
as to where or how to easily change the password without having to go into
the code builder(I.E.- a button that says "change password here" sort of
thing)? Thank you in advance. BTW I am using Access 2003 if that means
anything special.

Private Sub Text2_AfterUpdate()
Dim strpwd As String
Const conGoodPwd As String = "studio"
Dim intMaxTries As Integer

For intMaxTries = 1 To 3

If strpwd = conGoodPwd Then 'Good
DoCmd.OpenForm "Admin Form", acNormal
DoCmd.Close
Exit For
End If

Next intMaxTries

End Sub
 
R

Rick B

Okay, what prevents them from simply opening that form?

I have never seen a "good" reason to build a password in code in Access.
Use User-Level Security and secure the Admin form. If the user should not
be in it, don't give them access to it. Building a password like you have
includes way too many back doors. What prevents your users from opening the
code and seeing your password? What prevents them from simply opening the
table or the query and viewing or changing the data?

I would recommend (as I always do) building in security properly, using the
tools provided by Access.
 
S

schasteen

Rick is correct that any user with any knowledge can get around this type of
security, but for your knowledge the code does not set the value of strpwd.
You need to place strpwd = Me![Text2] or replace strpwd with Me![text2] in
your if statement. You could then make a table containing the password and
use Dlookup to get the value in your code, but nothing would stop the users
from openg the table and getting the password.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top