PDA

View Full Version : Password Protected userform



GreenDR
03-22-2013, 11:20 AM
Hi guys,

:think:
I'm looking for a way to ask the user for a password when he clicks the close icon of the form in MS Access.
--The form is opened automatically when database is opened.

if the password is correct, then
close the form
else
alert that password is incorrect and go back to the form.

Thanks in advance guys!:bow:

Dave
03-22-2013, 04:32 PM
Not sure about access but this works for XL. HTH. Dave

Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
Dim Password As String
If CloseMode = vbFormControlMenu Then
Password = Application.InputBox("Enter Password")
If Password = "Password" Then
Cancel = False
Else
MsgBox "Wrong password"
Cancel = True
End If
End If
End Sub