Determining user's group

  • Thread starter Thread starter BarbaraC
  • Start date Start date
B

BarbaraC

How can I determine if the currently logged-in user
belongs to a particular group? I have a button on a form
that is used to release medical results and only
the "pathologist" group should be allow to use the
button. I would like to make it invisible if the user is
not a member of that group - or display a message if an
unauthorized user pressed the button.
 
Try:


If ([DBEngine].[Workspaces](0).[Users](CurrentUser()).Groups(0).[Name] =
"pathologist") then
Me!button.visible = true
Else
Me!button.visible=false
End If


Rick
 
I don't think so: what if the user belongs to more than one group, and the
pathologist group isn't the first one?

Function IsUserInGroup (GroupName As String) As Boolean
Dim ws As WorkSpace
Dim usr As User
Dim intLoop As Integer

IsUserInGroup = False

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(CurrentUser())
For intLoop = 0 To usr.Groups.count - 1
If StrComp(Groups(intLoop).Name, GroupName, vbTextCompare) = 0 Then
IsUserInGroup = True
Exit For
End If
Next intLoop

End Function


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Rick said:
Try:


If ([DBEngine].[Workspaces](0).[Users](CurrentUser()).Groups(0).[Name] =
"pathologist") then
Me!button.visible = true
Else
Me!button.visible=false
End If


Rick

BarbaraC said:
How can I determine if the currently logged-in user
belongs to a particular group? I have a button on a form
that is used to release medical results and only
the "pathologist" group should be allow to use the
button. I would like to make it invisible if the user is
not a member of that group - or display a message if an
unauthorized user pressed the button.
 
The code I listed in my response works just fine in my database and everyone
in it is a member of 'users' first. The code I modified applies to members
of group 'manager' and it works just fine, even though they are members of
user (first) and manager.

Your code seems awful complex for something that can be done in five lines.

Rick





Douglas J. Steele said:
I don't think so: what if the user belongs to more than one group, and the
pathologist group isn't the first one?

Function IsUserInGroup (GroupName As String) As Boolean
Dim ws As WorkSpace
Dim usr As User
Dim intLoop As Integer

IsUserInGroup = False

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(CurrentUser())
For intLoop = 0 To usr.Groups.count - 1
If StrComp(Groups(intLoop).Name, GroupName, vbTextCompare) = 0 Then
IsUserInGroup = True
Exit For
End If
Next intLoop

End Function


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Rick said:
Try:


If ([DBEngine].[Workspaces](0).[Users](CurrentUser()).Groups(0).[Name] =
"pathologist") then
Me!button.visible = true
Else
Me!button.visible=false
End If


Rick

BarbaraC said:
How can I determine if the currently logged-in user
belongs to a particular group? I have a button on a form
that is used to release medical results and only
the "pathologist" group should be allow to use the
button. I would like to make it invisible if the user is
not a member of that group - or display a message if an
unauthorized user pressed the button.
 
They are not a member of users first. They are a member of manager first (m
comes before u) - actually I wouldn't even rely on that.

I just tested your example in one of my secure databases and it returned
false for the following
?dbengine.Workspaces(0).Users(currentuser()).Groups(0).Name = "wiki"
when the user was in fact a member of the wiki group.

You need to loop through all the groups to be certain, as Doug showed.
--
Joan Wild
Microsoft Access MVP

Rick said:
The code I listed in my response works just fine in my database and everyone
in it is a member of 'users' first. The code I modified applies to members
of group 'manager' and it works just fine, even though they are members of
user (first) and manager.

Your code seems awful complex for something that can be done in five lines.

Rick





Douglas J. Steele said:
I don't think so: what if the user belongs to more than one group, and the
pathologist group isn't the first one?

Function IsUserInGroup (GroupName As String) As Boolean
Dim ws As WorkSpace
Dim usr As User
Dim intLoop As Integer

IsUserInGroup = False

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(CurrentUser())
For intLoop = 0 To usr.Groups.count - 1
If StrComp(Groups(intLoop).Name, GroupName, vbTextCompare) = 0 Then
IsUserInGroup = True
Exit For
End If
Next intLoop

End Function


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Rick said:
Try:


If ([DBEngine].[Workspaces](0).[Users](CurrentUser()).Groups(0).[Name] =
"pathologist") then
Me!button.visible = true
Else
Me!button.visible=false
End If


Rick

How can I determine if the currently logged-in user
belongs to a particular group? I have a button on a form
that is used to release medical results and only
the "pathologist" group should be allow to use the
button. I would like to make it invisible if the user is
not a member of that group - or display a message if an
unauthorized user pressed the button.
 
Thanks, Joan and Doug. My bad.

I guess I have lucked out the few times I used this in my database and did
not do anything too complex with it. I will have to go back and revise my
code to be more universal.

Thanks again.

Rick

Joan Wild said:
They are not a member of users first. They are a member of manager first (m
comes before u) - actually I wouldn't even rely on that.

I just tested your example in one of my secure databases and it returned
false for the following
?dbengine.Workspaces(0).Users(currentuser()).Groups(0).Name = "wiki"
when the user was in fact a member of the wiki group.

You need to loop through all the groups to be certain, as Doug showed.
--
Joan Wild
Microsoft Access MVP

Rick said:
The code I listed in my response works just fine in my database and everyone
in it is a member of 'users' first. The code I modified applies to members
of group 'manager' and it works just fine, even though they are members of
user (first) and manager.

Your code seems awful complex for something that can be done in five lines.

Rick
([DBEngine].[Workspaces](0).[Users](CurrentUser()).Groups(0).[Name]
 
Needn't loop, surely!

on error resume next
s = dbengine(0).users(currentuser).groups("pathologist").name
bIsInGroup = (err.number = 0)
on error goto 0

Cheers,
TC

Joan Wild said:
They are not a member of users first. They are a member of manager first (m
comes before u) - actually I wouldn't even rely on that.

I just tested your example in one of my secure databases and it returned
false for the following
?dbengine.Workspaces(0).Users(currentuser()).Groups(0).Name = "wiki"
when the user was in fact a member of the wiki group.

You need to loop through all the groups to be certain, as Doug showed.
--
Joan Wild
Microsoft Access MVP

Rick said:
The code I listed in my response works just fine in my database and everyone
in it is a member of 'users' first. The code I modified applies to members
of group 'manager' and it works just fine, even though they are members of
user (first) and manager.

Your code seems awful complex for something that can be done in five lines.

Rick
([DBEngine].[Workspaces](0).[Users](CurrentUser()).Groups(0).[Name]
 
Thanks everyone! I was able to get it to work!
-----Original Message-----
Thanks, Joan and Doug. My bad.

I guess I have lucked out the few times I used this in my database and did
not do anything too complex with it. I will have to go back and revise my
code to be more universal.

Thanks again.

Rick

Joan Wild said:
They are not a member of users first. They are a
member of manager first
(m
comes before u) - actually I wouldn't even rely on that.

I just tested your example in one of my secure databases and it returned
false for the following
?dbengine.Workspaces(0).Users(currentuser()).Groups (0).Name = "wiki"
when the user was in fact a member of the wiki group.

You need to loop through all the groups to be certain, as Doug showed.
--
Joan Wild
Microsoft Access MVP

my database and
everyone modified applies to
members
though they are members
of
user (first) and manager.

Your code seems awful complex for something that can
be done in five
lines.
Rick





"Douglas J. Steele"
I don't think so: what if the user belongs to more
than one group, and
the
pathologist group isn't the first one?

Function IsUserInGroup (GroupName As String) As Boolean
Dim ws As WorkSpace
Dim usr As User
Dim intLoop As Integer

IsUserInGroup = False

Set ws = DBEngine.Workspaces(0)
Set usr = ws.Users(CurrentUser())
For intLoop = 0 To usr.Groups.count - 1
If StrComp(Groups(intLoop).Name, GroupName,
vbTextCompare) = 0
Then
IsUserInGroup = True
Exit For
End If
Next intLoop

End Function


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Try:


If
([DBEngine].[Workspaces](0).[Users](CurrentUser()).Groups (0).[Name]
=
"pathologist") then
Me!button.visible = true
Else
Me!button.visible=false
End If


Rick

How can I determine if the currently logged-in user
belongs to a particular group? I have a button on a form
that is used to release medical results and only
the "pathologist" group should be allow to use the
button. I would like to make it invisible if the user is
not a member of that group - or display a message if an
unauthorized user pressed the button.


.
 
Back
Top