Forum Discussion
Username from Office-Account with VBA (Access2016)?
I use the System.DirectoryServices.AccountManagement object to get user information on my apps.
In VB (I don't use VBA but very simliar syntax) the UserContext object give you all the information about the signed in user (Current) you need.
Imports System.DirectoryServices.AccountManagement
Dim User As UserPrincipal = UserPrincipal.Current
Dim UserContext As PrincipalContext = User.Context
Hope that helps.
I can help if you explain how to integrate the code you suggested in the Access VBA environment ...
- Don DeCarloOct 11, 2016Brass Contributor
Yes.
So you would create a object on your form (or other type) i.e. Label
Then you would create some code (i.e. VBA or Visual Basic)
Then you would reference the Netframework dll (using Imports) i think
Then create the sub and event (onLoad maybe) or click
So something like this. I just don't know the exact syntax in Access
Maybe you can get it working as you suggest.
Imports System.DirectoryServices.AccountManagement
Private Sub Label12_Click()
Dim User As System.DirectoryServices.AccountManagement.UserPrincipal
User = UserPrincipal.Current
Dim UserContext As System.DirectoryServices.AccountManagement.PrincipalContext
UserContext = User.Context
Label12 = User.DisplayName
End Sub- Paul EllerOct 20, 2016Copper Contributor
What means "Imports System.DirectoryServices.AccountManagement" and how can I reference to it that the types are known (MS Access 2016)?
Thanks for help
- Don DeCarloOct 20, 2016Brass Contributor
Dear Paul
I did a little more research and remembered that Access has a built in function that allows you to access the CurrentUser (Name and email) through a macro or VBA. So it is not necessary to use the reference inside your database for the System.DirectoryServices.AccountManagement.
Attached is a screen shot of how to add that function using a macro.
If you need more help I can prepare a step by step instruction to walk you through your exact requriements. Let me know.
Thanks
Don