Password Form

R

Renee

I have a main form that opens when I open my database file with two command
buttons; one of them is called office and it opens another form with more
command buttons. How can I set a password so that when someone clicks on the
Office button it asks for a password to open the next window? I would also
like it to show **** instead of the actual password.
 
R

Renee

I would also like it to go back to the main form if the password is incorrect
or open the office form if the password is correct.
 
R

Renee

That seems awfully complicated. I have this code so far in the 'on click'
event:

Private Sub OFFICE_Click()
On Error GoTo Err_OFFICE_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "OFFICE"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OFFICE_Click:
Exit Sub

Err_OFFICE_Click:
MsgBox Err.Description
Resume Exit_OFFICE_Click

End Sub

I am just not sure where to put a code for the password form to open first
then open my office form once the password is entered correctly.

Thank you.
 
A

Arvin Meyer [MVP]

Allright, change the line:

DoCmd.OpenForm stDocName, , , stLinkCriteria

to something like (untested):

DoCmd.OpenForm "frmPassword"

Then in the password form, have a textbox named txtPWD in in the AfterUpdate
event of txtPWD use the following code:

Sub txtPWD_AfterUpdate()
If Me.txtPWD = "Whatever you want the password to be" Then
Me.Visible = False
DoCmd.OpenForm "OFFICE"
Else
MsgBox "Sorry wrong Password", vbOKOnly, "Password Error!"
DoCmd.OpenForm "Name of first form"
End If
End Sub

I'd also put some code in the office form's open event to keep anyone from
opening it directly:

Sub Form_Open(Cancel As Integer)

If Not IsLoaded("frmPassword") Then
MsgBox "Open this form with a password", vbOKOnly, "Password Error!"
End If

You can also write some code to check the values of txtPWD to make sure it's
correct. Please note, the Microsoft KB article is probably a better way of
handling this than a makeshift method that can be easily circumvented by a
resourceful employee.
 

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