Hi, how can i get username and not eviron(Username) in access...
In excel we get different output for Application.Username and not Eviron("Username")
Thanks in advance for helping....
Hi, how can i get username and not eviron(Username) in access...
In excel we get different output for Application.Username and not Eviron("Username")
Thanks in advance for helping....
Hi Ped,
When I want to get the username of the current user I use the following function in VBA.
First I declare this in the top section of the vba code in the line before 'Option Compare Database'. Then I use this function in my code. Calling this should return the current user's username to the variable assigned to the function.
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 'Internal file reference for getting Windows username
'The fOSUserName function is used to get the username of the user currently logged onto the network.
Function fOSUserName() As String
'Initialise variables
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
Hope this helps.
Tom.
Thanks for replying...that is another way like environ("Username")
Now in access tools >> Popular >> username = Pedie Nz
and my environ username/computer id = Pedie2009
I'm trying to get the name...if that is posible...
Thanks again.
Pedie,
Did you ever find an answer to this? I am having the same problem.
Thanks in advance!
Kris
This works like a charm!
Function UserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
UserName = Left$(strUserName, lngLen - 1)
Else
UserName = vbNullString
End If
End Function
Is the computer you are using part of an active directory domain?
did anyone got this question resolved? I am also stuck on this. All I see are the network login / environ / and other username codes which shows the network username but not the access application username and initials.
tried this code but apparently access does not have "username" but have "currentuser".
any idea?
Code:Sub myName() Dim objaccess As Object Dim strUserName As String Set objaccess = GetObject(, "Access.Application") strUserName = objaccess.UserName Debug.Print strUserName End Sub
I typed into VBA immediate window:
?Application.CurrentUser
That returned:
Admin
Really don't understand what is being asked for.
Instead of hijacking ancient threads, should start your own. A new thread with no replies gets more attention. Can reference an older thread if you think it contributes info relevant to your issue.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
If you are not using Access security, which requires a user to log in to the database, the CurrentUser is always Admin.
The Environ function can only retrieve values from current environment variables. The network login ID is (usually) in the environment variable UserName.
Thanks June. not the user type/group but the actual username - the name you type upon initial load of ms office application (option > username). but after a few searches, i think this is not possible with access, hopefully Im wrong.
If it's saved anywhere, might be in a registry, at least that's where CurrentUser is pulled from. https://msdn.microsoft.com/en-us/lib...or=-2147217396
This talks about MS Office RegCompany and RegOwner properties http://www.pctools.com/guides/registry/detail/460/
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Thanks for the link June. However both deals with the "CurrentUser" or "Network Username". I tried to search the name within the application. try to run my code in excel:
This data is somewhat not readable in access.Code:Sub myName() Dim objaccess As Object Dim strUserName As String Set objaccess = GetObject(, "Excel.Application") strUserName = objaccess.UserName Debug.Print strUserName End Sub
Edited my earlier post (perhaps after you read it). There is another link.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Hi June, would you know how do I access them to show in access? VBA? Im on a network and does not have access to the registry. Thansk!
If you can't access the registry then don't see how you can do it with VBA. But what has network got to do with looking at registries on computer?
The links I found is the extent of my familiarity with this topic - which is essentially nil.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.