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

Security to a command button

Status
Not open for further replies.

goslincm

MIS
May 23, 2006
292
US
Hi, I used a suggestion out here to password protect one form within my database, however after the user is prompted to enter their password, the password is being display on the screen. How to I make it so this displays as an asterick instead of the actual password?

Dim strPasswd

strPasswd = InputBox("Enter Password", "Restricted Form")

'Check to see if there is any entry made to input box, or if
'cancel button is pressed. If no entry made then exit sub.

If strPasswd = "" Or strPasswd = Empty Then
MsgBox "No Input Provided", vbInformation, "Required Data"
Exit Sub
End If

'If correct password is entered open Date Input form
'If incorrect password entered give message and exit sub

If strPasswd = "StaffName" Then
DoCmd.OpenForm "dbo_XREF_CTV_Munfin", acViewNormal
Else
MsgBox "Sorry, you do not have access to this form", _
vbOKOnly, "Important Information"
Exit Sub
End If
End Sub
 
I don't think you can using an InputBox.

You would have to create a small form that contains a TextBox with the InputMask set to "*". Your command button on the calling form will open this "security check form" in Dialog Mode, so it can't be bypassed. The security check form will then do the checking of the password and either return to the calling form or open the "secured" form and then close itself.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
So I do not need the code with the password like I used, instead I should just have the form open to the new form that has the input mask?
 
Go into Design View of the table where the password resides, click just to the right of the box marked Input Mask, then click on the ellipsis (...) that pops up. Now select "Password" and save the table. Now the password will appear on screen as all *********.

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
goslincm,

The code on your starting form's command button should be something like:

Code:
DoCmd.OpenForm "frmSecurityCheck", , , , , acDialog
DoCmd.Close acForm, Me.Name

frmSecurityCheck will have a textbox, txtPassword, with the InputMask set to "*". Also add a command button called cmdCheckPassword. You can add labels and any other formatting you want to make it appear as you like.

The code behind cmdCheckPasword_Click should be something like:

Code:
If Me![txtPassword] = "" Or IsNull(Me![txtPassword]) Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
     End If
     
     If Me![txtPassword] = "StaffName" Then
        DoCmd.OpenForm "dbo_XREF_CTV_Munfin", acViewNormal
     Else
        MsgBox "Sorry, you do not have access to this form", _
                vbOKOnly, "Important Information"
        DoCmd.OpenForm "startingform"
     End If
     DoCmd.Close acForm, Me.Name

I also want to point out this is not truly "secure" way to lock a form. There are other ways in. You can search this site for several threads on the topic. The best way to lock a form such as this is to take advantage of Access' workgroup security. It can be a bit daunting to the first few times you deal with it, but will provide the best results overall. But this should get you by if it is not "super" sensitive...And will keep most casual users out.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Sorry to be ignorant but I'm not getting this quite yet. I created the security form and I have it open up when I call on my form for data input, however the text box field I have on it, the one with the input mask is an unbound field. Am I suppose to have a table where this password gets stored?
 
You don't need the password table unless you want different passwords for different people. In this instance, the code sample you provided had the password in it, So the sample I sent back in my last post also used that password.

An unbound textbox is not a bad thing. It merely means that the textbox does not have an associated field in a table or query somewhere. In fact, unbound textboxes can be used for a lot of different things. I have seen people use the to hold variables, calculate values, and a wide variety of other things.

Let me try to be a bit clearer though:

You have three forms:
- "frmStartForm" has a command button on it to "open" the secured form
- "frmSecurityCheck" is opened in dialog mode instead. This form has an unbound textbox called txtPassword and with an InputMask of *. There is also a command button called cmdCheckPassword. The user will enter the password of "StaffName" in this instance, as that is what the sample you supplied had. This password should show as only astericks due to the InputMask. When the user click the command button, the code in my last post is run.
- "frmSecuredForm" is opened if the password the user typed matches the one in the code, so "StaffName" in this case. If the password does not match, then frmSecurityCheck is closed and the user returns to frmStartForm.

As I was typing this, I realized you may be confused with the "StaffName" password thing. Are you gingt o have separate passwords for each eprson, or just one? If is just one, you can replace the "StaffName" with whatever password you want and then let the authorized users all know this one password. If you plan on having different passwords for each person, you will need a table to store this and then the code will change as well to account for that.

Hope this helps.... :)

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Not sure what is wrong in this but when I get the "sorry you do not have access" message, I am running into an error message instead of the form closing. "The expression you entered refers to an object that is closed or does not exist".

I know I missed something simple here but cannot see it.


Private Sub Command2_Click()
If Me![txtPassword] = "" Or IsNull(Me![txtPassword]) Then
MsgBox "No Input Provided", vbInformation, "Required Data"
Exit Sub
End If

If Me![txtPassword] = "ItWorks" Then
DoCmd.OpenForm "dbo_XREF_CTV_Munfin", acViewNormal
Else
MsgBox "Sorry, you do not have access to this form", _
vbOKOnly, "Important Information"
DoCmd.Close acForm, Me.Name
End If
DoCmd.Close acForm, Me.Name


End Sub
 
That is because you are closing the form twice....replace:

MsgBox "Sorry, you do not have access to this form", _
vbOKOnly, "Important Information"
DoCmd.Close acForm, Me.Name

with

MsgBox "Sorry, you do not have access to this form", _
vbOKOnly, "Important Information"
DoCmd.OpenForm "startingform"

Note the second line....:)

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top