Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    13

    Unanswered: NT Username in Access

    Hi,

    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.

    If anyone can suggest a better way of doing this, please do so. I'm sure JavaScript can't get NT usernames - can VBScript so this?

    I'm using IIS as the web server, Access 2000 as the database and IE6 as the client (so I can use VB Script or JavaScript). All operating systems are either NT or 2000.

    Failing that, I guess I can use a script that asks the user for his name the first time, stores it in a cookie and uses that for all future sessions. Any code, hints and tips on this particular use of cookies also welcome!

    Thanks!

    Kev

  2. #2
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    Try looking at the Environ Variable. I think to get NT User name is something like Environ("UserName").

    Hope this helps

  3. #3
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    13
    Hi Funkster,

    Could you please give me some context for the environ function?

    Where do I use it? In VBScript? In an Access module or macro?

    An example whould be much appreciated.

    Ta,

    Kev

  4. #4
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    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.

  5. #5
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    13
    Hi Funkster,

    Thanks for the help.

    I may have a problem, though, if the Access database is on my IIS server. Won't environ() pick up the server environment and not the client?

    Regards,

    Kevin

  6. #6
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    I'm sorry I've not had much experience with Access and IIS. I'll have an ask around and see if any of my colleagues know any more.

  7. #7
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    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.
    Option Explicit



    ' 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.
    Sub Get_User_Name()



    ' 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)



    ' Display the User Name
    MsgBox UserName
    End Sub

  8. #8
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    13
    Hi axsprog,

    Thanks for that.

    What other useful goodies are in advapi32.dll?

    Cheers,

    Kev

  9. #9
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    Not sure of all of the features (it is the only time I use it and for the reason you posted)
    but check out this link

    http://support.microsoft.com/default...b;en-us;190000

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •