put a password on a button in a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
PLEASE STOP POSTING THIS ALL OVER. One post per question PLEASE! For more
info, please read:
http://www.mvps.org/access/netiquette.htm.



As answered in one of your many other posts...

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.
 
I am not so sure you are correct that it will NOT open the form.
IMHO, you ARE opening the form and then IMMEDIATELY closing it with
your "DoCmd.Close" in your next statement.

The syntax is DoCmd.Close [objecttype, objectname], [save]
and
If you leave the objecttype and objectname arguments blank (the default
constant, acDefault, is assumed for objecttype), Microsoft Access
closes the active window.

The two events just happen faster than you can see. Try single step
debugging to prove my point.
 
Back
Top