Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    anthony@aahs.us is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    14

    CurrentUser()

    in Access 2013 the CurrentUser() is "Admin". How can uou change it to a user that has logged on through a simple form that has confirmed the user and their password?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850

  3. #3
    anthony@aahs.us is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    14
    That is the login form that I use, it does a good job at securing who gets in but the CurrentUser() is still set to the default "Admin" and I have been unsuccessful in my attempts to update the
    CurrentUser().

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    AFAIK you can't. Don't make any use of it.

    This will give you the name of the current user
    Code:
    Environ("UserName")
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    To expand on what Colin said, in older versions of Access (2003 and earlier) if you had the old ULS (User Level Security) implemented, then CurrentUser() would return the name of the user that had logged in through ULS. ULS is deprecated in newer versions so CurrentUser() won't do you any good.

    Environ("UserName") will return the name of the user logged into the Windows environment, but that may or may not be the same user name they use to log into your application. You may need to roll your own function for this.

  6. #6
    anthony@aahs.us is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    14
    I was able to confirm the username and assign it to a string, but how can I move it to the default value in a text box. I tried by going into the properties of the form and putting =Environ("UserName") in the default value of the field. But it returned an error " #Name? "

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,128
    Use that as the record source of the textbox
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    or with a bit of code in the appropriate event, probably the form or report open or load event

    me.username.defaultvalue=environ("Username")

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Be aware that the "Username" retrieved using "Environ("Username")" can/could be changed in Windows by using the SET command in a DOS window.
    (or you used to be able to change it)

    Here is an option:

    You can get the Windows logged in user name using the code at http://www.databasedev.co.uk/get_use...putername.html
    It looks like you are/could be using 64 bit Access, so you should also read this https://msdn.microsoft.com/en-us/lib...ffice.14).aspx

    (maybe also this -> https://social.msdn.microsoft.com/Fo...orum=accessdev)

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    It's my understanding from the Steve Bishop video that he has established usernames and passwords specific to the application. This is similar to Sean/Beetle's comment in post #5 related to Environ("username") and its usefulness to you.
    Steve's subsequent videos show you how to take the concept further and manage what users have access to.

  11. #11
    anthony@aahs.us is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    14
    I'm Still running into a wall and it could be because I am not explaining what I am trying to do properly.

    I have a subform and when it opens I want the default value of the control name "created by" to be the Environ("username").

    What do I put in the property sheet - Default Value of the control named "created by' in order to return the users name who has logged into windows.

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    What do I put in the property sheet - Default Value
    see post #8

  13. #13
    anthony@aahs.us is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2018
    Posts
    14
    I did that and it still returns #Name? instead of the users name

  14. #14
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    this is not a difficult task, perhaps it is time you showed the code you are actually using. Also confirm the datatype for your 'created by' field.

  15. #15
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    Even though Environ returns a string, in order to apply it to the Default Value property of a control you still need to wrap it in additional string delimiters

    Me!YourTextBox.DefaultValue = """" & Environ("Username") & """"

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. CurrentUser() Macro
    By Helystra in forum Macros
    Replies: 7
    Last Post: 12-09-2013, 10:55 PM
  2. Currentuser always returns "Admin"
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 09-21-2013, 02:27 PM
  3. Retrieve the currentuser from Users table (Acc2007)
    By psunilve in forum Programming
    Replies: 3
    Last Post: 04-08-2013, 02:37 PM
  4. CurrentUser()
    By OpsO in forum Access
    Replies: 8
    Last Post: 09-16-2010, 11:37 AM
  5. CurrentUser dependent data in formular
    By Patience in forum Access
    Replies: 1
    Last Post: 05-11-2010, 12:26 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