Password protect a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Access 2000 - I have a menu form with a command button it, this button simply
opens another form which is for data entry. Is it possible to have a
password pop up box when a user clicks on the command button, if they dont
know the password then the data entry form doesn't open. Any ideas anyone,
thanks...
 
Hi Matt,

I like to use a popup form to collect the password and call
it whenever I need to ask the user for one:

make a form

name --> usys_pw
(prefacing the name with "usys" means it is a user-system
object and will be hidden unless system objects are showing)
(form) caption --> Enter Password

label control
caption --> "Enter Password:"
(just so it shows up bigger than the titlebar)

textbox control
name --> EnterP
InputMask --> Password

code behind the form:

'-----------------------
Private Sub EnterP_AfterUpdate()
SetRight (Me.EnterP)
DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Open(Cancel As Integer)
SetPW
End Sub
'-----------------------

then, in a general module

'-----------------------

Dim gBooPW As Boolean

Function SetPW()
gBooPW = False
End Function

Function GetPW() As Boolean
GetPW = gBooPW
End Function

Function SetRight(pPW) As Boolean
'you can use other logic
'to determine the correct password
gBooPW = IIf(Nz(pPW) = "secret", True, False)
End Function
'-----------------------

then, in the Open event for the form you want to protect:

'-----------------------
Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "usys_pw", , , , , acDialog

If Not GetPW() Then
MsgBox "You may not open this form", , "Incorrect
password"
Cancel = True
Exit Sub
End If
End Sub
'-----------------------


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
ps, here are properties to set for the password form:

ScrollBars --> neither
RecordSelectors --> No
NavigationButtons --> No
DividingLines --> No
AutoResize --> Yes
AutoCenter --> Yes
PopUp --> Yes
Modal --> Yes

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
thanks crystal, thats tops

strive4peace said:
Hi Matt,

I like to use a popup form to collect the password and call
it whenever I need to ask the user for one:

make a form

name --> usys_pw
(prefacing the name with "usys" means it is a user-system
object and will be hidden unless system objects are showing)
(form) caption --> Enter Password

label control
caption --> "Enter Password:"
(just so it shows up bigger than the titlebar)

textbox control
name --> EnterP
InputMask --> Password

code behind the form:

'-----------------------
Private Sub EnterP_AfterUpdate()
SetRight (Me.EnterP)
DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Open(Cancel As Integer)
SetPW
End Sub
'-----------------------

then, in a general module

'-----------------------

Dim gBooPW As Boolean

Function SetPW()
gBooPW = False
End Function

Function GetPW() As Boolean
GetPW = gBooPW
End Function

Function SetRight(pPW) As Boolean
'you can use other logic
'to determine the correct password
gBooPW = IIf(Nz(pPW) = "secret", True, False)
End Function
'-----------------------

then, in the Open event for the form you want to protect:

'-----------------------
Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "usys_pw", , , , , acDialog

If Not GetPW() Then
MsgBox "You may not open this form", , "Incorrect
password"
Cancel = True
Exit Sub
End If
End Sub
'-----------------------


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
you're welcome, Matt ;) happy to help


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
Hi Crystal, if you do read this I have just tried to use this form on my DB.

I don't seem to have got it working right, I have created a form and
selected pop up yes, am I right to put a text box in it, when i do this and
put the text box control source to EnterP it doesn't accept anything, also
where is the actual password stored, what is the password.

Sorry if this makes no sense not done this before.

Thanks again
 
Hi Matt,

The password will NOT have a control source

the value will be in the textbox while it is being tested,
unless you WANT to store it...

EnterP is the NAME of the control, not its ControlSource...

The Name property is the top one listed on the Other and on
the All tab of the property window


Warm Regards,
Crystal
MVP Microsoft Access

remote programming and training
strive4peace2006 at yahoo.com
*
Have an awesome day ;)
 
Back
Top