# Access: Password protect a form?



## cliffrose (Jan 21, 2006)

Hi all,

i have one form I'd like to password protect. I found the following code online that I know will work: 

In ON CLICK event
Dim PassWord As String
PassWord = InputBox("Enter Password")
If PassWord = "YourPassword" Then
' Open Form
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord , , acNewRec
Else
MsgBox ("You're not authorized")
End If

but the problem is that this is tied to a button on the switchboard. I have 5 different switchboard pages, and if i tie this to the first button on the physical form (in the form section), I think it will require the password for the first button on all the pages.

is there a workaround or another way to do this?

TIA,

E


----------



## OBP (Mar 8, 2005)

E, if you put that in the Form's "On Load" Event Procedure and change it t0
Dim PassWord As String
PassWord = InputBox("Enter Password")
If PassWord = "YourPassword" Then
' Open Form
exit sub
Else
MsgBox ("You're not authorized")
DoCmd.Close acForm, Me.Name
End If

It should allow the form to remain open if the password is correct and close it if it isn't


----------



## cliffrose (Jan 21, 2006)

worked perfectly, thanks.

is there a way to have the typed letters in the input box come up as *** rather than the actual password being visible?

E


----------



## OBP (Mar 8, 2005)

Yes you can but it is VERY VERY HEAVY VBA code courtesy of Moviam on the VBAX Forum.
So do you want to give it a try?
It might be easier to Disable all of the Fields on the Form and Add the Password as an Unbound Text box on the Form, you can then use an Input Mask set to Password and use simple VBA to enable all the fields if the Password is correct.
I will have to go soon and we can continue this tomorrow.


----------



## cliffrose (Jan 21, 2006)

I'd love the experience with the heavy code, but the time i have left on this project is minimal......


----------



## OBP (Mar 8, 2005)

You can have the code, but if it proves problematic you would need to contact movian to resolve it.
See the attached database, you need the Module "Newboxes", which has the heavy Code and the simpler VBA code from the Password Entry Button and the Password Field, which does not need to be Visible, it is only there to show you it working.


----------



## cliffrose (Jan 21, 2006)

Thanks- I'll play with it for a bit- but today is my last official day on the project, so i may have to let it go...


----------

