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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows95 User Name 2

Status
Not open for further replies.

dvannoy

MIS
Joined
May 4, 2001
Messages
2,765
Location
US
Does Anyone know what the user Login Name within Windows95 is called...

On one of my forms I have this command
username = Environ("username")

Which will stamp the user's name who updates the record. it works fine for win2000 and NT but will not work with 95.

Thanks in advance
DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
This was taken from the Access Web:



API: Get Login name
--------------------------------------------------------------------------------


(Q) How do I retrieve the UserName with which the user is logged into the network?

(A) Paste the following code in a new module and call the function fOSUserName.


'******************** Code Start **************************
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSUserName() 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
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = &quot;&quot;
End If
End Function

'******************** Code End **************************
Joe Miller
joe.miller@flotech.net
 
Thanks for the info...Where do I call this function or will it automatically stamp the user name?

Thanks DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
Place the Function in a module and save it. Sset the default value of a control to =fOSUserName() and it will be put in automatically on new records. Or you can use it just as your were using the Environ() function.

Joe Miller
joe.miller@flotech.net
 
if i try and put the module in place of the Environ function it gives me this error Expected Variable or Procedure not Module..

If i put it the default value of the field it gives no errors but comes back blank..

DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
The username is not available on all 9x systems . . if a user presses escape for instance at the Win95 login, there will be no username to capture. The code does work, I tested it on 2000, 98, 95 & NT.

Joe Miller
joe.miller@flotech.net
 
I am using Access 97. I have tried putting the code below for getting username in a module, then in my form using the following code:

Me!Text = fOSUserName()

I keep getting an error &quot;Expected variable or procedure, not module&quot;

Please tell me what I'm doing wrong!!! I know it's something simpe, I just can't come up with it.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top