473,395 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Get current user's group name?

How can I get the current user's group name within a database? I'd like to set certain properties based on who is logged in. I have found many descriptions of how to get the Windows user name, but I want the names and groups assigned in the MDW file, not the Windows name.

Thanks!
Oct 25 '10 #1

✓ answered by ADezii

Expand|Select|Wrap|Line Numbers
  1. Dim wrkDefault As Workspace
  2. Dim grp As Group
  3. Dim usr As User
  4.  
  5. Set wrkDefault = DBEngine.Workspaces(0)
  6.  
  7. Debug.Print "Groups to which " & CurrentUser; " belongs: (non-secured DB)"
  8. Debug.Print "-------------------------------"
  9.  
  10. For Each grp In wrkDefault.Groups
  11.   For Each usr In grp.Users
  12.     If usr.Name = CurrentUser() Then
  13.       Debug.Print grp.Name
  14.     End If
  15.   Next
  16. Next
  17.  
  18. Debug.Print "-------------------------------"
  19.  
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Groups to which Admin belongs: (non-secured DB)
  2. -------------------------------
  3. Admins
  4. Users
  5. -------------------------------

4 7344
Never mind, I found the answer:

DBEngine(0).Users(CurrentUser).Groups(GroupName).N ame
Oct 25 '10 #2
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Dim wrkDefault As Workspace
  2. Dim grp As Group
  3. Dim usr As User
  4.  
  5. Set wrkDefault = DBEngine.Workspaces(0)
  6.  
  7. Debug.Print "Groups to which " & CurrentUser; " belongs: (non-secured DB)"
  8. Debug.Print "-------------------------------"
  9.  
  10. For Each grp In wrkDefault.Groups
  11.   For Each usr In grp.Users
  12.     If usr.Name = CurrentUser() Then
  13.       Debug.Print grp.Name
  14.     End If
  15.   Next
  16. Next
  17.  
  18. Debug.Print "-------------------------------"
  19.  
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Groups to which Admin belongs: (non-secured DB)
  2. -------------------------------
  3. Admins
  4. Users
  5. -------------------------------
Oct 25 '10 #3
ADezii
8,834 Expert 8TB
I failed to mention why I posted this obviously longer solution. Not sure if this is your case, but a User can belong to several Groups, with the Least Restrictive Rule taking effect.
Oct 26 '10 #4
Great, thanks!
Oct 26 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MJB | last post by:
I know I can get the current username through the System.Environment class, but I can't seem to find where I can retrieve the user's role / permission level (i.e. Admin, power user, etc). If...
2
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some...
0
by: Giovanni Bassi | last post by:
Hello Group, I using impersonation on my web app. I am explicitely setting the User with the identity element in the web.config like this: <identity impersonate="true" userName="MyUsr"...
4
by: Dan Bart | last post by:
I am using an application which is a modification of IBuySpy Portal. It is using Forms authentication. Users login and their name is added to Context Then I use: ...
13
by: Steve Enzer | last post by:
How can I get the login name of the user currently logged into Windows as a string? Thanks, Steve Enzer
4
by: cpajoe2001 | last post by:
I am not sure if this is the proper place to put this thread but I have run into a road block. I am writing a web app that will create groups in Active Directory then add users to those groups. I...
9
by: Victor | last post by:
Hi all Does anyone has any reference or examples about how to customize the httpcontext.current.user object to my own user object? Cheers Victor
4
by: Doogie | last post by:
Hi, I am using HttpContext.Current.User.Identity.Name to get a user id from a web application. I then use that as part of a name of a cookie I'm writing. 30 minutes later I do a refresh of this...
5
by: Max2006 | last post by:
Hi, I am trying to limit my wcf service endpoint to response to only given windows user or group. How can I do that? Is there any way to configure that in the .config file? Thank you, Max
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.