Protecting specific fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I created a form which allows users to add/update records. There are
specific fields in the form that I only want the managers to be able to
update. Is there a way to restrict specific controls (i.e. lock property)
for some users but allowing managers to update?
 
Yes. Just do an if statement in your form's load event and set the locked
property of the field based on the userid of the person opening the form.
You could do a search, as this type of question is asked and answered pretty
often.

You could also do this based on their "group" but you would have to create a
function out there that determines if they are in a particular group. You
could do a search to find that code.

Rick B
 
Thanks for your response. However, this is my first time in this site, and
I've been searching for awhile and still can not find the exact code to do
this. I've seen similar posts but nothing with the exact code how to do
this. Would you please be able to provide the code, as I am not experienced
in VB programming. I appreciate your help!
 
Searching google for "isingroup", I found the following. Some of these may
help you do what you want. I have not tested any of this.

Rick B

---------------------------------------------------------------
In a standard code module paste this code:

CODE
Public Function IsInGroup(Target, Pattern) As Boolean
If Nz(Pattern, "*") = "*" Then IsInGroup = True: Exit Function
Dim i As Long
For i = 1 To Len(Pattern)
If InStr(Target, Mid(Pattern, i, 1)) > 0 Then
IsInGroup = True: Exit Function
End If
Next i
End Function

---------------------------------

Go to the following link and do a 'find' on the page. There is a link about
halfway down the page that will take you to an actual sample database with
the code built in.

http://www.rogersaccesslibrary.com/OtherLibraries.asp

The link is called, "Function IsInGroup Sample Database (IsInGroup.mdb) (8
KB) Access 97 "

---------------------------------

Check this out...

Here's a link to a previous discussion on this subject. It includes the code
for a 'IsInGroup' function that will return True if the specified user is in
the specified group ...

http://www.google.com/[email protected]

---------------------------------

You can do this...but it often result in a LOT of work.

I usually hide all of the ms-access bars.

Then, for my own menus like special options (to add new users etc), I simply
remove the permissions form the form. Then, users that don't have
permissions simply can't use those forms. Not a very friendly default
message is given...but then again users quickly learn that they simply can't
use certain options. This approach saves tons of coding on your part. And,
further..you should be hiding all of the built in tool bars anyway.

However, if you must, you could use some start-up code like:

if IsInGroup(CurrentUser,"SuperUser" then

CommandBars("menu bar").Controls("records").Controls("refresh").Visible
= True

end if
\
if IsInGroup(CurrentUser(),"InvoideDeleteGroup") = true then

CommandBars("myCustomBar").Controls("AdminOptions").Controls("DleeteInvoice"
).Visible = True

end if

You then need the folwign code IsInGroup in a global modeule:

Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName

Dim grp As Group
Dim IIG As Boolean
Dim usr As user

IIG = False

For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = UsrName Then GoTo FoundUser
Next

GoTo IIG_Exit

FoundUser:
For Each grp In usr.Groups
If grp.Name = GrpName Then IIG = True
Next

IIG_Exit:
IsInGroup = IIG

End Function
 
Thank you, I will try these.

Rick B said:
Searching google for "isingroup", I found the following. Some of these may
help you do what you want. I have not tested any of this.

Rick B

---------------------------------------------------------------
In a standard code module paste this code:

CODE
Public Function IsInGroup(Target, Pattern) As Boolean
If Nz(Pattern, "*") = "*" Then IsInGroup = True: Exit Function
Dim i As Long
For i = 1 To Len(Pattern)
If InStr(Target, Mid(Pattern, i, 1)) > 0 Then
IsInGroup = True: Exit Function
End If
Next i
End Function

---------------------------------

Go to the following link and do a 'find' on the page. There is a link about
halfway down the page that will take you to an actual sample database with
the code built in.

http://www.rogersaccesslibrary.com/OtherLibraries.asp

The link is called, "Function IsInGroup Sample Database (IsInGroup.mdb) (8
KB) Access 97 "

---------------------------------

Check this out...

Here's a link to a previous discussion on this subject. It includes the code
for a 'IsInGroup' function that will return True if the specified user is in
the specified group ...

http://www.google.com/[email protected]

---------------------------------

You can do this...but it often result in a LOT of work.

I usually hide all of the ms-access bars.

Then, for my own menus like special options (to add new users etc), I simply
remove the permissions form the form. Then, users that don't have
permissions simply can't use those forms. Not a very friendly default
message is given...but then again users quickly learn that they simply can't
use certain options. This approach saves tons of coding on your part. And,
further..you should be hiding all of the built in tool bars anyway.

However, if you must, you could use some start-up code like:

if IsInGroup(CurrentUser,"SuperUser" then

CommandBars("menu bar").Controls("records").Controls("refresh").Visible
= True

end if
\
if IsInGroup(CurrentUser(),"InvoideDeleteGroup") = true then

CommandBars("myCustomBar").Controls("AdminOptions").Controls("DleeteInvoice"
).Visible = True

end if

You then need the folwign code IsInGroup in a global modeule:

Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of GrpName

Dim grp As Group
Dim IIG As Boolean
Dim usr As user

IIG = False

For Each usr In DBEngine.Workspaces(0).Users
If usr.Name = UsrName Then GoTo FoundUser
Next

GoTo IIG_Exit

FoundUser:
For Each grp In usr.Groups
If grp.Name = GrpName Then IIG = True
Next

IIG_Exit:
IsInGroup = IIG

End Function
 
Back
Top