Results 1 to 10 of 10
  1. #1
    Wayan71 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    9

    How to put “username” after login on MainMenu

    I have a login form built in Microsoft Access. The User will login through it and make it to the MainMenu form.

    How do we put the Welcome "Username" on the MainMenu form? ( Not PC UserName)



    User123
    Password : 12345

    On Mainmenu wil be KiranaWyn

    I use below VBA


    Code:
    Option Compare Database
    Private Sub Command1_Click()
    
    Dim ID As Integer
    Dim TempUserID As TempVar
    
    If IsNull(Me.txtLoginID) Then
        MsgBox "Enter the username", vbInformation, "Login ID required"
        Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
        MsgBox "Enter password", vbInformation, "Password required"
        Me.txtPassword.SetFocus
    Else
        If (IsNull(DLookup("UserID", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
            MsgBox "Invalid Login ID or Password!"
        Else
                ID = DLookup("[Userid]", "tblUser", "[UserLogin] = '" & Me.txtLoginID.Value & "'")
                TempVars!TempUserID = ID  'assign user login ID to tempvar
                DoCmd.Close
                DoCmd.OpenForm "MainMenu"
            
        End If
    End If
    End Sub
    
    Private Sub Form_Load()
    Me.txtLoginID.SetFocus End Sub
    Last edited by Wayan71; 05-16-2021 at 04:53 AM.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Well you would need some way of identifying user123 as KiranaWyn, as you already have, so perhaps use Dlookup() to get the real name using the username?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Wayan71 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    9
    Please help how

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    I don't understand?
    You are using Dlookup() already, to get a userid that has been keyed in?
    You just do the same, but return UserName instead?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  6. #6
    Wayan71 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    9
    Dear Welshgasman

    Do you mean :

    Me.UsrName = DLookup(“[UserName]”, "tblUser", "[UserLogin] = '" & Me.txtLoginID.Value & "'")

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Well along those lines. Except your control, is called User?

    Also I just noticed that you do not actually have a field called UserID in the table?

    You have to get the names EXACTLY correct. You and I might know what you mean, but a computer does not.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Wayan71 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    9
    Dear Welshgasman ,

    Could you please help me how to resolved this issue, ( see
    attachment)

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Against my better judgement , as I normally prompt the O/P to write their own code, so as to understand what they are doing.
    You will need to review the code I added and the control source for the form control. Which is really just the DLookUp I mentioned previously, but using correct names.

    You could also set it via form load and not use the control source.

    For some reason, your DB does not behave well on my laptop?
    Attached Files Attached Files
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Wayan71 is offline Novice
    Windows 10 Office 365
    Join Date
    May 2021
    Posts
    9
    Dear Welshgasman ,

    Thank you for your help,

    Well Done!

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

Similar Threads

  1. Replies: 47
    Last Post: 05-10-2021, 01:59 PM
  2. Access - Login Form and Store ID/Username
    By RiskIt in forum Access
    Replies: 3
    Last Post: 01-07-2019, 03:08 AM
  3. Replies: 3
    Last Post: 02-21-2017, 07:52 AM
  4. Username and passwod login using Form
    By Tom1 in forum Programming
    Replies: 4
    Last Post: 07-04-2012, 12:29 PM
  5. Recording UserName Login
    By Moonsitter53 in forum Access
    Replies: 1
    Last Post: 03-18-2011, 02:40 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