Password Protection

J

Jamie Dickerson

I would like to password protect a few forms. I have searched the postings
and tried a few suggestions but with little or no success. I have played
around with ULS but it seems to be more trouble than its worth (in my case).
I am looking for the easiest solution possible. I consider myself a novice ,
but I do not have a ton of time to put towards this project.

Thank You in Advance for Your Help.

Jamie
 
B

BruceM

To prevent them from being opened? To make them read-only? What have you
tried? Without knowing that it may be difficult to avoid repeating what you
have already tried.
 
J

Jamie Dickerson

I would like to prevent them from being opened. I played with Read-Only ULS
but as I said seems to be more trouble than its worth as I would have to add
every possible user. I have also tried building a module with help from the
Microsoft Support website. That required new tables, forms, etc. I just
thought there would be an easier way about this.

What I was hoping to do was put a code in the On_Open for each form which
requests a password and if the correct one is entered the form opens. I plan
 
D

Damon Heron

If its something that simple, check out the InputBox in Help. You could add
the code in the form load or open event that requests a pwd in the inputbox,
and if not correct, close form.

Damon
 
B

BruceM

One possibility is to use the code here to get the network login name:
http://www.mvps.org/access/api/api0008.htm

The function is named fOSUserName(). To use it you could do something like
this in the form's Open event:

Private Sub Form_Open(Cancel As Integer)

Dim strUser as String
Dim blnOK as String

strUser = fOSUserName
' Debug.Print strUser
' MsgBox strUser
blnOK = (strUser = "YourLoginName")

cmdOne.Visible = blnOK
cndTwo.Visible = blnOK

End Sub

You could add either the Debug line or the MsgBox line to verify the
function is returning the expected value.

cmdOne and cmdTwo are command button's to open the forms.

Another option is to use a popup form in the Open event of a restricted
form:

DoCmd.OpenForm "frmPassword", , , , , acDialog

In frmPassword, a text box named txtPassword and a command button. In the
command button's Click event:

If Me.txtPassword = "YourPassword" Then
DoCmd.OpenForm "frmMain"
Else
MsgBox "Invalid password", vbInformation, "Password Error"
DoCmd.Close acForm, "frmMain"
End If

If you would need the code for more than one form you could pass the name of
the form in the OpenArgs argument of OpenForm:

Dim strFrm as String
strFrm = Me.Name

DoCmd.OpenForm "frmPassword", , , , , acDialog, strFrm

Then in the Click event on frmPassword:

Dim strArgs as String
strArgs = Me.OpenArgs

If Me.txtPassword = "YourPassword" Then
DoCmd.OpenForm strArgs
Else
MsgBox "Invalid password", vbInformation, "Password Error"
DoCmd.Close acForm, strArgs
End If

Please note that this will help keep honest people honest, nothing more.
The fOSUserName function is probably more secure. User Level Security is
better yet. I have found Jack MacDonald's security paper here to be of
great value in explaining how ULS works:
http://www.geocities.com/jacksonmacd/
 
J

Jamie Dickerson

Thank You Both for your help. I used a combination of the two and it works
perfectly. I even made sure that the switchboard would not open the forms.
Again your help is appreciated.
 

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

Top