Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting username

Status
Not open for further replies.

RamziSaab

MIS
May 7, 2003
522
GB
is there a way to get the username of the person logged in from windows in access?
 
Take a look at the following thread for a discussion on this issue and some code:

thread705-569862
 
Dear Ramzi,

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 = &quot;&quot;
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 [2thumbsup]






Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
it ok thanks for ur help, but using

=Environ(&quot;username&quot;)

...much easer :)
 
Try this:

Declare Function GetUserNameA Lib &quot;advapi32.dll&quot; (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetUserName() As String

Dim UserName As String * 255
Call GetUserNameA(UserName, 255)
GetUserName = Left$(UserName, InStr(UserName, Chr$(0)) - 1)

End Function
 
loet me do what jrbarnett nicely did to me and refer u to the following thread

Thread705-569862

short answer is no..but really people its time to upgrade if it doesnt :)
 
Dear Ramzi,

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.

Enjoy,
Hap...

Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
Dear Ramzi,

No offense taken,

You can tell it is lunch time and I am just bored.

Bottom line, I just need more things to do to keep me busy...

Good Luck and Have a Great Day,
Hap...

Access Developer [pc] - [americanflag]
Specializing in Access based Add-on Solutions for the Developer
 
Hi

Using Environ(&quot;Username&quot;) 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.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top