Password protecting a form

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

I am trying to protect a form from the command button that opens it. This
is what I am using

Dim sPassword As String
Const sAccess = "PASSWORD"
sPassword = InputBox("PLEASE ENTER THE PASSWORD", "PASSWORD")
If sPassword <> sAccess Then
Cancel = True


Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmAdmin"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If


This works through the enter password and then it just returns back to the
origional form.

Greg
The Oft Access Confused
 
Greg,

If I am not mistaken, Const declarations need to be declared
in the General (Header) section of a module, not within the
Sub procedure. In this case, you don't really need a Const,
just a normal variable unless you need also to refer to it
elsewhere.

You are also missing an else statement so that even if the
password does match, it is exiting the IF and never opens
the form as the OpenForm is inside the IF statement. Try
this variation.

Dim sPassword As String, sAccess as String
sAccess = "PASSWORD"
sPassword = InputBox("PLEASE ENTER THE PASSWORD",
"PASSWORD")
If sPassword <> sAccess Then
Cancel = True
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmAdmin"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Gary Miller
Sisters, OR
 
Back
Top