Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Security / November 2005

Tip: Looking for answers? Try searching our database.

Show/Hide controls depeding on User's wrkgrp Group

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Walter - 26 Nov 2005 11:25 GMT
Hello

How do i determine what wrkgrp Group the User belongs to during a Form's
OnOpen event?

Walter
Brendan Reynolds - 26 Nov 2005 11:45 GMT
'DAO method - requires DAO reference
Public Function IsUserInGroupD( _
       ByVal UserName As String, _
       ByVal GroupName As String _
       ) As Boolean

   Dim usr As DAO.User
   Dim grp As DAO.Group

   Set usr = DBEngine.Workspaces(0).Users(UserName)
   For Each grp In usr.Groups
       If grp.Name = GroupName Then
           IsUserInGroupD = True
           Exit For
       End If
   Next grp

End Function

'ADOX method - requires ADOX reference
Public Function IsUserInGroupA( _
       ByVal UserName As String, _
       ByVal GroupName As String _
       ) As Boolean

   Dim cat As ADOX.Catalog
   Dim usr As ADOX.User
   Dim grp As ADOX.Group

   Set cat = New ADOX.Catalog
   Set cat.ActiveConnection = CurrentProject.Connection
   Set usr = cat.Users(UserName)
   For Each grp In usr.Groups
       If grp.Name = GroupName Then
           IsUserInGroupA = True
           Exit For
       End If
   Next grp

End Function

Examples of use, in the Immediate window ...

? isuseringroupd(currentuser(),"Admins")
True
? isuseringroupd(currentuser(),"Test")
False
? isuseringroupa(currentuser(),"Admins")
True
? isuseringroupa(currentuser(),"Test")
False

Signature

Brendan Reynolds

> Hello
>
> How do i determine what wrkgrp Group the User belongs to during a Form's
> OnOpen event?
>
> Walter
Walter - 26 Nov 2005 12:53 GMT
Thanks Brendan.

>'DAO method - requires DAO reference
>
>'ADOX method - requires ADOX reference
>? isuseringroupa(currentuser(),"Test")
>False
TC - 26 Nov 2005 23:37 GMT
> Public Function IsUserInGroupD( _
>         ByVal UserName As String, _
[quoted text clipped - 10 lines]
>     Next grp
> End Function

Why iterate? You can test it directly, without having to loop. Also,
that code will fail with a runtime error if the specified user does not
exist.

This version returns True if the specified user exists AND the
specified group exists AND the specified user is a member of the
specified group - False otherwise:

Public Function IsUserInGroup( _
        UserName As String, _
        GroupName As String _
        ) As Boolean
dim s as string
on error resume next
s = dbengine(0)(0).users(UserName).groups(GroupName).name
isuseringroup = (err.number = 0)
End Function

Cheers,
TC
Brendan Reynolds - 27 Nov 2005 12:36 GMT
> Why iterate? You can test it directly, without having to loop.

Why not iterate? There would have to be tens of thousands of users and
groups before there would be any perceptible impact on performance.

> Also,
> that code will fail with a runtime error if the specified user does not
> exist.

Rightly so. Attempting to refer to a non-existant user is an error and
should be treated as such. Determining whether a user or a group exist is a
separate operation from determining whether a user is a member of a
specified group. They should be separate functions or, at the least, if they
are combined the function should return different results to distingusih
between the various possibilities - user and group exist, user is in group,
user and group exist, user is not in group, user exists, group doesn't, user
does not exist, group does.

IMHO of course! :-)

Signature

Brendan Reynolds

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.