Results 1 to 8 of 8
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209

    #Name?


    I have a form, that I added textbox to, and I want the textbox to display the windows user name that is inputting the data. So I put =winusername() in the Default value of the text box, but it is producing only #Name? Please help

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    did you define the function winusername()? or you just assume that Access should have that function built in?

    I get the windows user name by a user defined function "username()" as following(in a module):
    Code:
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Function UserName() As String
        Dim lngLen As Long
        Dim strBuffer As String
        
        Const dhcMaxUserName = 255
        
        strBuffer = Space(dhcMaxUserName)
        lngLen = dhcMaxUserName
        If CBool(GetUserName(strBuffer, lngLen)) Then
            UserName = Left$(strBuffer, lngLen - 1)
        Else
            UserName = "NoUser"
        End If
    End Function

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use the Environ() function or this:

    http://www.mvps.org/access/api/api0008.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    I tried both codes, but it is still displaying #Name?. My remaining question is:

    When I input the function into a module, how do I tell access to call this function from the textbox that I want the username input in? Or does access automatically regonize the funtion and will display the username once the function has been input?

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Access will look for it.

    when I tried, it works. not sure where you stuck.

  6. #6
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    Just to make sure I do it correctly. I would hit F10 to open up VBA editor, and then say insert module. From there I would copy and paste the code, and name the code whatever. Once the code is inserted, I would go back to my textbox, and in the default value insert =winusername() and access should display the windows name correcT?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For the method I posted, you would copy/paste the code as-is into a new module, name the module anything but "fOSUserName", then in your textbox:

    =fOSUserName()
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    Nevermind, I didn't change the =winusername to =UserName and that is where the error was coming into play. Thanks for the help!

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums