Results 1 to 11 of 11
  1. #1
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22

    Retrieve Windows Username and then lookup value

    Okay so I have a field that displays the active windows user, for example: seans

    we use first name last initial for windows login. However I want to display full name formatted properly. (i.e.) Sean Schaeffer

    I assume a table with full names is needed and then a query but for the life of me I cant figure out how to tie it all together.

    ideas?

  2. #2
    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 DLookup() or open a recordset to get the full name from your table of full names, using the Windows user as the criteria.

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    If you are using Active Directory you can get info from it. When a User is created in AD, there is an option for entering the user's full name. This example demonstrates how to get info from AD for the current user.

    https://www.accessforums.net/program...tml#post281033



    .

  4. #4
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22
    Do you put DLookup in VBA or just in Control Source?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by iDeals View Post
    Do you put DLookup in VBA or just in Control Source?
    Either, depending on your needs.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22
    okay, here are my results.

    when my form loads I use the following to populate a textbox:

    Code:
    Private Sub Form_Load()
    Me.Text35 = Environ("UserName")
    End Sub
    which gives me the active windows user.

    I have tried to following to get the proper name to no avail:

    Code:
    Private Sub Form_Load()
    Me.Text35 = Environ("UserName")
    Me.Text49 = DLookUp([DisplayName],[tblActiveUser],[Criteria]=[Me].[Text35].[Value])
    End Sub
    It didn't like that so I tried the following in the control source:

    =DLookUp([DisplayName],[tblActiveUser],[Criteria]=[Me].[Text35].[Value])
    and
    =DLookUp([DisplayName],[tblActiveUser],[Criteria]=Environ("UserName"))

    to which I get a #Name? error

  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
    See if this helps:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Access doesn't recognize Environ() - only in VBA.

    Following Paul's excellent examples - static parameters for the arguments go within quote marks and filter argument text parameters require apostrophe delimiters.

    =DLookUp("[DisplayName]", "[tblActiveUser]", "[Criteria]='" & [Text35] & "'")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll get out of the way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22
    that's what I referenced initially for the Dlookup structure. Played around a bit more but no dice.

  11. #11
    iDeals is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2015
    Posts
    22
    Quote Originally Posted by June7 View Post
    Access doesn't recognize Environ() - only in VBA.

    Following Paul's excellent examples - static parameters for the arguments go within quote marks and filter argument text parameters require apostrophe delimiters.

    =DLookUp("[DisplayName]", "[tblActiveUser]", "[Criteria]='" & [Text35] & "'")
    Perfection! Thank you June & Paul!

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

Similar Threads

  1. Replies: 14
    Last Post: 08-17-2015, 02:32 AM
  2. Windows Username Authentication
    By james28 in forum Security
    Replies: 2
    Last Post: 04-30-2014, 02:55 PM
  3. Windows Log In "Username" in an append query
    By jlgray0127 in forum Queries
    Replies: 1
    Last Post: 02-26-2013, 09:46 AM
  4. Replies: 5
    Last Post: 08-08-2012, 01:28 PM
  5. Replies: 3
    Last Post: 07-15-2010, 05:53 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