+ Reply to Thread
Results 1 to 8 of 8

Showing user name in TextBox

  1. #1
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Showing user name in TextBox

    Hi all,

    I was just wondering if Access has an equivalent to Excel's Application.UserName function in VBA.

    Basically I'm trying to display the current user's full name in a TextBox on a form rather than their username.

    So for me it would show something like Beth Davis rather than DAVISB.

    It would be easy if I could have a table to store the UserName and full name of each user, but what I'm building will sit on a network and have hundreds of users with a high turnover so nobody will want to maintain that list.

    Thanks in advance for any suggestions. I'm very new to Access!

    Beth.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,167

    Re: Showing user name in TextBox

    From what I know,
    application.username will not work in access.

    I suppose you could get the username function from excel in access

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Re: Showing user name in TextBox

    Thanks for that. It is an option I may have to fall back on and it certainly works once I've turned on the Excel reference in the VBE.

    Problem is that Excel takes so long to open on my organisation's network that opening it just to get the user's name seems like an unnecessary stall.

    I may try adding a table to the database with UserName as one field and User's Full Name as another. Then when the user opens the main form it can check if the UserName exists in that table. If so then look up full name and carry on, if not they enter their name in a mini form that updates that table and they carry on. Next time they open it their UserName will be in the list so they'll only have to do it once and no table maintenance required. (I don't know how to do any of that yet, but I'm sure I'll figure it out)

    OR, I may try connecting it to the Outlook GAL and extracting the detail based on the UserName. (I've done this in Excel so should be possible)

    All just feels like I'm over complicating things. Application.UserName works fine in Excel and in Word, so why not in Access?

    Beth.

  4. #4
    Forum Guru
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Showing user name in TextBox

    Dave's response uses 'Early Binding' which requires the library reference.

    The following modification to Dave's excellent response uses 'Late Binding' which does NOT require the library reference:
    Please Login or Register  to view this content.
    I do not have Microsoft Access. The above routine did work for me from Outlook.

    For a discussion of the differences between 'Early Binding' and 'Late Binding' see https://wordmvp.com/FAQs/InterDev/Ea...ateBinding.htm

    Lewis
    Last edited by LJMetzger; 11-10-2019 at 02:17 PM.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    1,888

    Re: Showing user name in TextBox

    Quote Originally Posted by BanginMyHeadOnMyDesk View Post
    ... if Access has an equivalent to Excel's Application.UserName function in VBA ...
    You can also use the API ( GetUserName ) or WMI ( GetObject ("winmgmts:") ):

    https://docs.microsoft.com/en-us/off...to-the-network
    https://social.msdn.microsoft.com/Fo...a?forum=isvvba
    https://docs.microsoft.com/pl-pl/win...ectedfrom=MSDN

  6. #6
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Re: Showing user name in TextBox

    Quote Originally Posted by LJMetzger View Post
    Dave's response uses 'Early Binding' which requires the library reference.

    The following modification to Dave's excellent response uses 'Late Binding' which does NOT require the library reference:
    Thanks Lewis. I'm aware of the Early/Late binding thing and do plan on trying it when I'm back in the office tomorrow morning.
    I'm not convinced it will have any effect on the slow opening time of Excel just to get a user's name though (I know you're not implying it will help)

    Quote Originally Posted by porucha vevrku View Post
    You can also use the API ( GetUserName ) or WMI ( GetObject ("winmgmts:") ):
    Thanks also porucha vevrku, I will have a look into API/WMI.

    Beth.

  7. #7
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,677

    Re: Showing user name in TextBox

    How about ...

    Please Login or Register  to view this content.
    That may not be the same as Application.UserName, which is set in Office.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Re: Showing user name in TextBox

    Thanks shg, I will give that a try too.

    When I test it here at home (not on a network) it gives me the same as Environ("UserName") (i.e. DavisB rather than Beth Davis) but I won't know for sure until I can test it on the network tomorrow morning.

    I shall report back!

    Beth.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. showing Labels and Textbox values
    By zaku in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-17-2015, 12:30 PM
  2. [SOLVED] Showing tooltip in a textbox
    By szpt9m in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2014, 06:20 AM
  3. Not showing value time in TextBox and ListBox
    By Seeuw in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-14-2013, 06:27 AM
  4. vba excel user form restrict input on user textbox
    By samz93 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2013, 04:38 PM
  5. Showing a user name in a message box if a workbook is read only by that user
    By derryt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2012, 05:01 AM
  6. showing cell value in textbox
    By surfinglaverty in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2010, 10:02 AM
  7. [SOLVED] Showing a calculation in a userform Textbox
    By jamie.rowland@shell.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-03-2006, 08:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1