Password protecting a form

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
 
G

Gary Miller

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Hiding typed text 1
Simple Password Help 1
Hiding text for passwords 1
A2000 form ceases working under A2002 1
Input box question 2
Password locking a Form 3
filter on combo box possible? 1
Password Prompt 1

Top