[AccessD] Get User Name

Bobby Heid bheid at appdevgrp.com
Wed Sep 1 07:33:40 CDT 2004


Hi Karen,

I use this (note that I did not write this):

Private Declare Function GetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

' Returns the network login name or 'Admin' if api call fails
Public Function GetOSUserName() As String
Dim lngLen  	As Long
Dim lngX    	As Long
Dim strUserName 	As String

   On Error GoTo Proc_Err

   strUserName = String$(254, 0)
   lngLen = 255
   lngX = GetUserName(strUserName, lngLen)
   If lngX <> 0 Then
      GetOSUserName = Left$(strUserName, lngLen - 1)
      Else
         GetOSUserName = "ADMIN"
      End If
   
Proc_Exit:
   Exit Function
    
Proc_Err:
    MsgBox Err.Number & " - " & Err.Description, vbExclamation + vbOKOnly ,
"GetOSUserName"
   Resume Proc_Exit

End Function

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Nicholson, Karen
Sent: Wednesday, September 01, 2004 8:19 AM
To: accessd at databaseadvisors.com
Subject: [AccessD] Get User Name


It is great to be back on the list and working with Access again.  It has
been a while.  I am looking for the user defined function to grab the
network user name or id.  I have inherited an Access 2002/SQL 2000 back-end
database run completely by macros with a pretty bad password scenario.  This
should keep me busy for a while.

Karen Nicholson
National Laboratory
Xerox Global Services


-- 
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list