Assigning a code to a button on a switch board

tony7ana

Registered User.
Local time
Yesterday, 22:07
Joined
Aug 2, 2012
Messages
13
All,

I am working on a switch board in Access 2007 which has 2 buttons. Each button allows users to open a different form. One form is for all users, the other form I want to restrict to certain people only to be able to enter. I have created an on click input box that will ask the user for the password. How do I assign the below code to this button so it will allow access to the people with the password only? I have no idea how to assign a code to a button. I tried to run in it module, but did not work. Your help is appreciated!!!!

If InputBox("Password") = "password" Then
DoCmd.CancelEvent
Else
MsgBox "You are not authorized!", vbOKOnly
DoCmd.Close
End If
 
Maybe you should place the security on the FORM and not on the Switchboard Button that opens the form, becasue if users somehow get into your Navigation Pane they will still be able to open the form by clickin on IT directly.

Set your security in the ON_OPEN event of the form..

Private Sub Form_Open(Cancel As Integer)
'Setup your variables
Dim strResp As String
Dim strPSWD As String

'Define your password
strPSWD = "MYPASSWORD"

'Pop up an input box to get your password
strResp = InputBox("Enter the Password", "Restricted Access")
'compare the input to the password you defined
If strResp = strPSWD Then
'Do Nothing and the form will open as usual"
Else
MsgBox "You are not authorized!", vbOKOnly
DoCmd.Close acDefault
End If​
End Sub
-Goh
 
I think there might be a problem with the code. It is identifying the correct password, however, i tested it by entering incorrect passwords. It will let me know that I am not authorized, however, it will still open the Form that i am trying to secure automatically after the "not authorized" statement is given.

I tried to play with the code but it is still not working, any ideas?????
 
OOPS, my bad, it's in the middle of an event...
DoCmd.CancelEvent
-Goh
 

Users who are viewing this thread

Back
Top Bottom