Results 1 to 3 of 3
  1. #1
    KiEESH is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2013
    Posts
    4

    Environ("username") ---> #Name? Error

    Hello-

    I'm trying to display Windows username on a form and also have it write to the associated field in my table.

    I successfully accomplished this using the same code (below) in a different form in my DB.



    However, when I use the code in a new form within that same DB, I get the #Name? error.

    The error occurs even when the Private Sub is commented out and the Public function stands alone.

    The only change I made was to the field name.


    Triple-checked the accuracy in spelling and syntax.
    Also added "=GetUserName() to the control as a source.

    Issue still present.


    Please help! Completely stumped.


    Code:
    Public Function GetUserName() As String
    
    GetUserName = Environ("UserName")
    
    End Function
    
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    Me![ADDED_BY] = GetUserName()
    
    End Sub

  2. #2
    qa12dx is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    india
    Posts
    112
    =currentuser()

    i think it has changed with version. when i used it last was in access 2000, and it was user(). not sure. anyway i checked the above in my access 2007 and it works.

  3. #3
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Why two steps?

    Have you tried:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.[ADDED_BY] = Environ("UserName")
    End Sub
    Also changed the Bang! to a period

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

Similar Threads

  1. Replies: 1
    Last Post: 02-17-2013, 04:46 PM
  2. Replies: 4
    Last Post: 07-25-2012, 04:01 AM
  3. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  4. Replies: 2
    Last Post: 11-04-2011, 02:45 AM
  5. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM

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