Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    cariboy is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10

    current user name display on form

    Good day


    I created a database in Access 2010 and now after opening it in Office 365 i found some of the functions previously done not working properly. I would be happy if I can get some help on one of the issues in my database now; I would like to display the current user of the database based on the person's User Login and not the Environ (computer's name). The fields in my table are User Name, User Login, Password, User Security. Below is the code i currently have and worked in the previous version of access.

    Code:
    Private Sub Command1_Click()
    Dim TempPass As String
    Dim ID As Integer
    Dim UserName As String
    Dim AccessLevel As Integer
    
    
    If IsNull(Me.TxtLoginID) Then
        MsgBox "Please enter LoginID", vbInformation, "LoginID Required"
        Me.TxtLoginID.SetFocus
    ElseIf IsNull(Me.TxtPassword) Then
        MsgBox "Please enter Password", vbInformation, "Password Required"
        Me.TxtPassword.SetFocus
    Else
        'process the job
      If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin ='" & Me.TxtLoginID.Value & "'  And password = '" & Me.TxtPassword.Value & "'"))) Then
            MsgBox "Incorrect LoginID or Password"
        Else
                TempPass = DLookup("password", "tblUser", "UserLogin = '" & Me.TxtLoginID.Value & "'")
                UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.TxtLoginID.Value & "'")
                ID = DLookup("UserID", "tblUser", "UserLogin = '" & Me.TxtLoginID.Value & "'")
                AccessLevel = DLookup("UserSecurity", "tblUser", "UserLogin = '" & Me.TxtLoginID.Value & "'")
                DoCmd.Close
        If (TempPass = "password") Then
            MsgBox "Please Change Password", vbInformation, "New Password Required"
            DoCmd.OpenForm "tblUser", , , "[UserID] =" & ID
        Else
            DoCmd.OpenForm "MAIN SCREEN"
            Forms![MAIN SCREEN]![TxtUser] = UserName
            Forms![MAIN SCREEN]![txtsecurity] = AccessLevel
            
                    Call Security(AccessLevel)
                    
        End If
    End If
    End If
    End Sub
    .

    All of this work if i use the CurrentUser = Environ ("UserName") but i dont want to use the environ name i want the name of the person based on their Username and Password which come from the user table in my database. Thanks for any help.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    So user inputs a login ID and password and you do lookup to Users table to verify user and retrieve UserName. That's what code appears to do. What happens - error message, wrong result, nothing?
    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.

  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
    So what exactly does "not working properly" mean? Do you get an error, if so what is it and on what line?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    cariboy is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    Thanks for the reply. Nothing happens (populate in txtUser textbox) login works fine and because there is no username the restrictions button works fine.

  5. #5
    cariboy is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    The User Name box on my form does not populate only does when i use currentuser = Environ ("Username") which i dont want to you. It worked in access 2010 but now that i'm using access in office 365 is does not populate

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    And why is the username not found with the DLookup? Have you step debugged? Are variables populated with expected data?
    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.

  7. #7
    cariboy is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    Hi June. Nothing is showing up in that text box. The only time it populates is when I use the environ("username") function. Then it returns the name of the computer, not the person using the custom login info for the database.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    cariboy is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    thanks but i dont know how to do that i would prefer not to since it has information that identify the company i work for and i dont want to have that information public

  10. #10
    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 understand. Perhaps a stand-alone sample with enough to replicate the problem? I can't replicate the problem, so can't say what's going wrong for you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I've looked 3x in the code and can't find "CurrentUser".
    i found some of the functions previously done not working properly
    Kinda looks like maybe you're missing a function call to CurrentUser, but you indicate this db was created in an earlier version but doesn't run in 2016 version. I'm using W10 and Access 2016 as are you, so if you want to copy the necessary objects into a test db and post, I should be able to look at it for you as well. While I have seen function calls that would run in earlier versions that would not in newer versions, it seems odd that the posted code would be a problem - unless maybe you're missing a function call. Just make sure you include some usable data in a user table if you post a db.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    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,725

  13. #13
    cariboy is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    Thanks for your reply. I believe the issue is, like you said, it might be the dlookup function to carry out this particular command does not work in Access 2016, since if i remember clearly it was working perfect in Access 2010. I have replaced the dlookup function with the CurrentUser that is CurrentUser=Environ(UserName) and the computer name (environ) rather than the user login from the database is displayed in the box and the restrictions to the command button works ( just in case you dont recall, i had it set up to allow access to a command button (admin) based on a user login info. this info comes from a table in the database. I will try to make a copy of the database and delete a lot of the object (tables, forms etc) leaving only the user info table, and the switchboard and try to upload it (i have no idea how to upload the database here (:

  14. #14
    cariboy is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    10
    This is the tutorial i used to create the DLookup to preform the restriction and to show the name of the current user.

    https://www.youtube.com/watch?v=6GCTqYLTeH8


    https://www.youtube.com/watch?v=j55_4eYnTEM&t=608s

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Follow instructions at bottom of my post.
    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.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-27-2016, 07:36 PM
  2. Replies: 13
    Last Post: 10-02-2014, 09:29 AM
  3. Display query results on user form
    By Ganesh7299 in forum Access
    Replies: 3
    Last Post: 12-28-2013, 06:19 AM
  4. Replies: 6
    Last Post: 02-21-2013, 10:52 AM
  5. Replies: 7
    Last Post: 02-13-2013, 12:55 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