Marc:
RBear is absolutely correct, but in case you're in an environment where you
don't actually need real security, and work with people who 1) have no idea
how to view code or even what Access or vba are and 2) don't have the time,
interest, or wherewithal to find out how to do anything in item 1, and your
data isn't security-critical (like credit cards or employee review stats),
you can do the following:
I did this because no one at my job was computer savvy whatsoever, so there
was 0 threat. Again, RBear is right that if you actually need security in
case someone knows what they're doing and also want to bypass the password;
I repeat, this is a workaround for dealing with complete newbs, and probably
isn't even that efficient codewise:
I made a password form with the password input box (form named
frmDesignPass), and in the onclick event of the button "OK" to proceed, I
have this:
If Nz(Me.DesignPass) = "password" Then
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.Close acForm, "MainMenu"
DoCmd.Close acForm, "frmDesignPass"
stDocName = "frmDesMenu"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
MsgBox "Password not correct for Design Department...please try
again", vbOKOnly, "Incorrect Password"
Me.DesignPass = ""
Me.DesignPass.SetFocus
End If
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
Select Case Err.Number
Case 94
Resume Next
Case 2501
DoCmd.OpenForm "MainMenu"
Case Else
MsgBox Err.Number & Err.Description
Resume Exit_Command3_Click
End Select
End Sub
So the password form, which you have open before the form you're trying to
protect, is frmDesignPass. The password in the above example is "password".
The "protected" form is frmDesMenu. I have the swtchboard (MainMenu) open
if they hit "cancel" on the password form instead of inputting a password.
You could also just make an inputbox for the password open in the onopen
event of the "protected" form, but then you need to do a lot of error
handling so the "protected" form doesn't just open when something errors on
the inputbox.
Again, not secure, and again, probably not efficient. I only used it
because no one using my app had any computer knowledge whatsoever, and the
data wasn't really all that significant, we just didn't want the wrong
departments using the wrong forms.