Restrict data updates

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

How does one use security to permit a user to change
existing data in a table in a specific field in the record
without allowing them to change data in any other fields
in the same record?

For example I have a form based on a Contacts table. Two
groups have permissions to access the table:

1. Read only (managers, sales persons)
2. Data entry (data processors with full data entry/edit
permissions)

I would like to permit certain staff members to update the
data in the Contacts table in one field only (a date
field) in the record but not give them the same latitude
as the full Data entry operators.

TIA,

Rick
 
Assuming they have no direct access to the tables, you can determine if the
current user is a member of a certain group, and then lock all the controls
on the form except the one.

There is code in the security FAQ you can use to determine if a user is a
member of a group.
 
Joan:

Thank you for your suggestion. Can you be a little more
specific for a novice. I have located the FAQ version
2.42 October,2000 and assume you are referring to question
23 which provides the code for several functions related
to listing users and groups.

Are all of these functions required to get to where I want
to go or is it only necessary to copy one or two of the
functions into my DB?


Rick
 
I presume you have a group set up for these users that are allowed to edit
the one control.

Use the last function in section 22
faq_IsUserInGroup

In the Open event for your form
If faq_IsUserInGroup("Production", CurrentUser()) then

lock/unlock various controls

Else
unlock/lock various controls
End if
 
Joan:

Yes I have one group for the updates and the additional
information when applied works great.

Final question. I have about 65 controls on the form and
its subforms. Any way to lock everything globally with
one line of code and then unlock the only field needed for
updates or do I have to list all the "Me!control.Locked =
True" for all the controls?

Rick
 
I would suggest a simpler approach. Lock all the controls in design view of
the form.

Then in your code all you need to do is

If...
TheOneControl.Locked = false
else
TheOneControl.locked = true
end if
 
Joan:

Sorry, am I missing something. If I lock all the controls
in design mode won't the data operators be locked out of
all the input fields on the form?

I have two groups using the form:

DataGroup (must be able to populate all fields)
TaxGroup (must be able to populate only one date field)

Rick
 
Actually, I missed something. thought you only had two groups.

So yes, you could loop through the controls on the form...

For Each ctl in Me.Controls
If not ctl.Name = "whatever" then
ctl.Locked = True
else
ctl.Locked = False
end if
Next ctl

You'll need to add error handling for the controls that don't have a locked
property.
 
Joan:

Following is my attempt to write the code for a user
belonging to the TaxGroup to open the Contacts form and be
restricted from entering data in all but two fields.

I get over 70 error messages stating:
"Object doesn't support this property or method"

Can you see what I am doing wrong?

Rick



Private Sub Form_Open(Cancel As Integer)

On Error GoTo Err_NotAvailable

If faq_IsUserInGroup("TaxGroup", CurrentUser()) Then
For Each ctl In Me.Controls

If Not ctl.Name = "conT1Reviewer" Or "conT1DateReview" Then
ctl.Locked = True

Else
ctl.Locked = False
End If
Next ctl

Err_NotAvailable:
MsgBox Err.Description
Resume Next
End If
End Sub
 
Hi Rick, You're likely getting that error because not all controls have a
locked property.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_FormOpen

Dim ctl as Control

If faq_IsUserInGroup("TaxGroup", CurrentUser()) Then

For Each ctl in Me.Controls
On Error Resume Next
If ctl.Name = "conT1Reviewer" Or ctl.Name = "conT1DateReview" then
ctl.Locked = false
else
ctl.Locked = true
end if
Next ctl

Else

For Each ctl in Me.Controls
On error resume Next
ctl.Locked = false
Next ctl

End if

Exit_FormOpen:
Exit Sub

Err_FormOpen:
MsgBox Err.Description
Resume Exit_FormOpen

End Sub
 
Joan:

Thank you so much for your patience with a "slow learner."
You assistance is much appreciated.

Rick
 
Back
Top