Unfortunately, that method is not available in Access. However, I knew you can run some Excel methods from Access. For example, the following code should do the job.
Public Function GetUserXLFullName() As String 'email@example.com '7/3/2020 Dim xlApp As Object Set xlApp = CreateObject("Excel.Application") GetUserXLFullName = xlApp.Application.UserName Set xlApp = Nothing End Function
But on the other hand, I also know I have used code to query the Active Directory before. As an example, here is a link to a function on my website on how to get the user's email address from Active Directory.
So, based on that example, a simple modification is all we need to get the user's Full Name from Active Directory. For instance:
Public Function GetUserADFullName() As String 'firstname.lastname@example.org '7/3/2020 Dim objADInfo As Object Dim objADUser As Object Set objADInfo = CreateObject("ADSystemInfo") Set objADUser = GetObject("LDAP://" & objADInfo.UserName) GetUserADFullName = objADUser.FullName Set objADUser = Nothing Set objADInfo = Nothing End Function
While testing these two approaches, I discovered using the Active Directory method to be faster than using Excel. Please let me know if your experience is the same. Also, please tell us if you know another method of retrieving the user's full name from the system. Thank you for reading. Cheers!