Txt and users levels?

D

d9pierce

Hi all,
Is there a way to display on forms a message "You have permission to
unlock records" & "You do not have permission to unlock records"
depending on user levels? I have a record locking chkbox on each form
to eliminate data change by accident. In my industry, one can be
viewing a record, a call comes in, someone hits the key board by
accident, changes a record, and it is changed. I do also have ifdirty
but not everyone always does the right thing so I added a chk to
unlock records so you only check this if you intend to edit or add
records. Any suggestions?
Thanks
Dave
 
A

Albert D. Kallal

Hi all,
Is there a way to display on forms a message "You have permission to
unlock records" & "You do not have permission to unlock records"
depending on user levels?

Yes, when you open the form, in the forms on-load event you could put the
following code:

if IsInGroup(CurrentUser,"SuperUser" then

me.txtMsg = "You have permission to unlock records"

else

me.txtMsg = "You have permission to unlock records"

end if

The above example assumes you have a un-bound text box on the form called
txtMsg, and the user is a member of the security group called "SuperUser".
Of course you replace "SuperUser" with the name you used for the security
group that a person is a member of that allows edits (and, change the name
of txtMsg to the name of the text box you choose on your form.

The funciton IsInGroup is not built into ms-access, but the code for that is
easy. Simply place the follow code in a standard public module (not the
forms module)

Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of a security group 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
 
D

d9pierce

Yes, when you open the form, in the forms on-load event you could put the
following code:

if IsInGroup(CurrentUser,"SuperUser" then

   me.txtMsg = "You have permission to unlock records"

else

   me.txtMsg = "You have permission to unlock records"

end if

The above example assumes you have a un-bound text box on the form called
txtMsg, and the user is a member of the security group called "SuperUser"..
Of course you replace "SuperUser" with the name you used for the security
group that a person is a member of that allows edits (and, change the name
of txtMsg to the name of the text box you choose on your form.

The funciton IsInGroup is not built into ms-access, but the code for thatis
easy. Simply place the follow code in a standard public module (not the
forms module)

Public Function IsInGroup(UsrName As String, GrpName As String) As Boolean
'Determines whether UsrName is a member of a security group 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

You are just to wonderful! Thanks
Dave
 

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