I'm writing a simple web app to record phone calls - similar to a helpdesk program - and I will be using MS Access and ASP.
As the app will be on my Intranet, and as I don't require users to log in to the Intranet, I can't get the username from the ASP server properties.
Does anyone know a way to get the NT username from the client using Access? What I would like is a macro (or something) that runs when a new record is created, gets the username from the client and inserts it into a field on the table that stores the new record.
I use it on the load event of my opening form in Access. I set a global variable called glbUserName = Environ("UserName"). I can then use this variable anywhere in my code to write back the value to an audit table when records are changed.
Alternatively you can set the Default value of a field in your table to =Environ("UserName") This way when ever a user creates a new record in that table it records the NT Username automatically alongside the information.
XL7: Visual Basic Procedure To Get Current User Name
Last reviewed: September 3, 1997
Article ID: Q152970
' Makes sure all variables are dimensioned in each subroutine.
' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
' Main routine to Dimension variables, retrieve user name
' and display answer.
' Dimension variables
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
' Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)