Place this code in a Module: [Blue]
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetOSUserName() 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
GetOSUserName = Left$(strUserName, lngLen - 1)
Else
GetOSUserName = ""
End If
End Function
[Black]
Now Place text box on your form or wherever:
1): [Blue] Define a text box on your form( Call it ShowNetWorkName) [Black]
2): [Blue] Place this code in the Form Load Event:
Me.ShowNetworkName = GetOSUserName
[Black]
Hope This Helps,
Hap
In a perfect world everyone would have the new intel 3.2 gig hrtz machine , 2 gig of memory and Access XP.
I do not work in that world, so I must support whatever version of Access my Customers would like.
I will tell you that there are probably more programs written in Access 97 then any other version. And this version of Access worked very well! I adapt based on the needs of my customer and I develop knowing that my users may have Access 97 on up and may be using Access or SQL for their data backend.
I have Access 2.0, Access 95, Access 97, Access 2000 and Access XP all running. I need to satisfy whatever my customers request, because the customer is always right.
Using Environ("Username" isn't so much the version of access, but the operating system that the computer is running. The Environ function will only work out of the box on Windows NT, 2000 and XP. It will NOT work on Windows 95/98 (have not tested on Me, but think it will fail).
Why? The Environ function works by reading environment variables (open a command prompt and type SET to see what is in there).
The operating systems on which it works intialise a lot more than those that it doesn't. The VBA code calling the API functions work on all versions.
I agree that you can put lines in autoexec.bat to set up some of the machines, but setting the username according to who logs onto the network will prove problematic if the machine is shared between users.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.