SQL Server Performance

Access 2002

Discussion in 'Performance Tuning for DBAs' started by naseem, Mar 4, 2003.

  1. naseem New Member

    I have an Access database running under Windows 2000.

    I want to get hold of the "username" logged on the machine, from within Access and store this user name in the Access database.

    Is there a system variable that contains the "username" obtainable within Access?

    Many thanks
  2. trifunk New Member

    I don't think there is a system variable available to Access directly but if you're using VBA in Access then you can retrieve the current logged on user using the GetUserName api like below (although this was used in VB)

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

    Public Function GetUserName() As String
    Dim szBuffer As String
    Dim lpSize As Long
    Dim lpRV As Long

    lpSize = 255
    szBuffer = String(lpSize, &H0)

    lpRV = GetUserNameAPI(szBuffer, lpSize)

    If lpRV <> 0 Then
    ' -1 to remove trailing null character
    GetUserName = Left(szBuffer, lpSize - 1)
    GetUserName = ""
    End If
    End Function


    World Domination Through Superior Software

Share This Page