Application.UserName Equivalent in MS Access

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Does anyone have VBA code that I can use in MS Access that provides the same data as Application.UserName as used in MS Excel?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
This only gives first name while the Excel equivalent gives the first and last name.
 
Upvote 0
I think you will need to roll your own.?
Google throws up lots of options, but I could not find one returning what you are asking?

Have you thought about accessessing AD?
 
Upvote 0
I don't know how to access AD, hence the thread.
 
Upvote 0
There are API functions and also WMI. A quick search should get you what you need.
 
Upvote 0
I don't know how to access AD, hence the thread.
Well, I always start with a Google.?
Just create a function that calls Excel then.? However while that will show my name on my personal computer, if I was in a works setting I would expect it not to show who I am? as I would be using a company ID like 317859456.

When I created a DB for a bank I worked for, I just had a table with the userid as above and the users name, level etc. If they were not in the table, they could not use the DB. It did not mater which computer was used.?
 
Upvote 0
I found the following code:-

Code:
Public Function GetUserADFullName() As String
'https://thedbguy.blogspot.com/2020/07/get-users-full-name.html

    Dim objADInfo As Object
    Dim objADUser As Object
    
    On Error GoTo ErrorHandler
    
    Set objADInfo = CreateObject("ADSystemInfo")
    Set objADUser = GetObject("LDAP://" & objADInfo.UserName) 'ERROR HERE
    
    GetUserADFullName = objADUser.FullName
    
    Set objADUser = Nothing
    Set objADInfo = Nothing
    
ErrorHandler:
    If Err.Number <> 0 Then
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbInformation, "basUtilities - GetUserADFullName"
    End If

End Function

However I get an error as indicated above.

-2147023564: Automation error
No mapping between account names and security IDs was done.
 
Upvote 0
Do you use active directory are your users logged onto the domain? That won't work if you don't - your comment about the Envrion("username") only returning the first name indicates that you may not.

Application.Username only returns the name that was typed in when office was installed - it could be anything
 
Upvote 0
OK I see what you mean. I wonder how Excel is able to do this?
 
Upvote 0

Forum statistics

Threads
1,221,531
Messages
6,160,361
Members
451,642
Latest member
mirofa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top