allow certain users access to fields in a form

K

K. Boomer

I would like to know if it is possible to password protect about 10 fields of
a 30 field form, so that only users with the password can edit the 10 fields.
I'd like the remaining 20 fields to remain available for editing without the
password. The 10 fields are important to the whole form, but should only be
changed by accounting staff.
 
L

Linq Adams via AccessMonster.com

Isolating the fields you want to control is fairly easy; you simply place a
value in the Tag property of each control and then loop thru the controls to
lock/unlock them, based on the Tag property. In Design View you can select
all ten controls, then goto Properties - Other and enter

Protected

***without*** quotation marks.

Then this is the basic code you'll need

Private Sub Form_Current()
Dim ctrl As Control

For Each ctrl In Me.Controls
If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox) Then
If ctrl.Tag = "Protected" Then
ctrl.Locked = True
End If
End If
Next

End Sub

Private Sub UnLockControls_Click()
Dim ctrl As Control
'Check for password here, if passes Then
For Each ctrl In Me.Controls
If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is ComboBox) Then
If ctrl.Tag = "Protected" Then
ctrl.Locked = False
End If
End If
Next
'End If 'Uncomment this line after Password code above is in place
End Sub

This second piece of code above is where you'll put your code for the
password.Now you need to decide what kind of password protection you want,
based on how important this is.

Do you want to hardwire a password in code, then tell only authorized people
the password? This is the simplest, but requires going into the code if you
need to change the password.

Do you want each authorized person to have their own username/password? More
complicated, it requires having a separate table to hold the
usernames/passwords. You then have to compare the username in this table and
check it against the password entered. You also have to make provisions for
entering the usernames/passwords initially.
 
K

K. Boomer

Thank you very much for your response. I'm so glad I'll be able to password
protect some of the fields in my form. To answer your question to me, I
would like to hardwire a password in code and then give that password to a
few select people. So, based on that, how do I go about adding the password
in code?

Thanks for your time.
 
K

K. Boomer

Hoping Linq is available to continue assistance with my question. See below.

Thanks for your time.
 
Top