Results 1 to 4 of 4
  1. #1
    mister_tech is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    2

    Adding Logged in User Name to Wlecome Screen

    How to add the name of logged in user to a text box on main page after login?

    Below is the code I'm using. The login portion works, I cant get the user's Name from the Employees table to show up in a text box on the COM_Main form.

    Private Sub Command1_Click()
    Dim User As String
    Dim UserLevel As Integer
    Dim TempPass As String
    Dim ID As Integer
    Dim TempLoginID As String
    Dim WorkerName As String
    If IsNull(Me.txtLoginID) Then
    MsgBox "Please enter a Login ID", vbInformation, "LoginID Required"
    Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter a Password", vbInformation, "Password Required"
    Me.txtPassword.SetFocus

    Else
    'process the job
    If (IsNull(DLookup("UserName", "Employees", "UserName='" & Me.txtLoginID & "'"))) Or _
    (IsNull(DLookup("Password", "Employees", "Password ='" & Me.txtPassword.Value & "'"))) Then


    MsgBox "Incorrect LoginID or Password"
    Else
    TempLoginID = Me.txtLoginID.Value
    WorkerName = DLookup("UserName", "Employees", "UserName = '" & Me.txtLoginID.Value & "'")
    UserLevel = DLookup("UserLevel", "Employees", "UserName = '" & Me.txtLoginID.Value & "'")
    TempPass = DLookup("Password", "Employees", "UserName = '" & Me.txtLoginID.Value & "'")
    ID = DLookup("ID", "Employees", "UserName = '" & Me.txtLoginID.Value & "'")
    DoCmd.Close
    If (TempPass = "password") Then
    MsgBox "Please change your password", vbInformation, "New Password Required!"
    DoCmd.OpenForm "Change Password", , , "[ID] = " & ID
    MsgBox "After you changed your password, please login with your new password", vbInformation, "New Password Required!"
    Else
    'Open different form accrding to user level
    If UserLevel = 1 Then 'for admin
    DoCmd.OpenForm "COM_Main"
    Forms![COM_Main]![txtLoggedinUser] = Me.txtLoginID
    Forms![COM_Main]![txtMyName] = WorkerName

    Else
    ' If UserLevel <> 1 Then
    DoCmd.OpenForm "COMSECPHYSEC_Main"
    Forms![COMSECPHYSEC_Main]![txtLoggedinUser] = TempLoginID
    Forms![COMSECPHYSEC_Main]!NavigationButton11.Enabled = False
    Forms![COMSECPHYSEC_Main]![txtMyName] = WorkerName

    'Else
    'End If

    End If
    End If

    End If

    End If
    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe after you are done authenticating the user name and password you can bind the form to the Employees table using where Criteria that limits the RecordSet to the appropriate record/Employee.

  3. #3
    mister_tech is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    2
    How do I do that? I created this from a tutorial but I couldn't get the logged in user's name to show...

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    According to your code, you already assign the user to the textbox control named txtLoggedinUser on your form named COM_Main.

    Here you declare a variable.
    Code:
    Dim TempLoginID As String
    Here you assign the value typed by the user to your variable.
    Code:
    TempLoginID = Me.txtLoginID.Value
    Here you are assigning the variable to something on your form.
    Code:
    Forms![COMSECPHYSEC_Main]![txtLoggedinUser] = TempLoginID
    And you are doing something similar with...
    Code:
    Forms![COM_Main]![txtMyName] = WorkerName
    Apparently, you are using unbound forms. Perhaps you have a control named txtLoggedinUser that is not bound to anything.
    So maybe the dot operator would be more appropriate than the bang access operator.
    Code:
    Forms![COMSECPHYSEC_Main].[txtLoggedinUser] = TempLoginID

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

Similar Threads

  1. Logged In user Names
    By Parminder in forum Access
    Replies: 5
    Last Post: 07-23-2015, 02:17 PM
  2. Access 2010 : Current logged in user
    By raghav_pegausis in forum Access
    Replies: 7
    Last Post: 10-24-2011, 02:52 PM
  3. logged user name on main form
    By foxtet in forum Forms
    Replies: 1
    Last Post: 07-30-2011, 03:00 PM
  4. Getusername of currently logged in user
    By nkuebelbeck in forum Access
    Replies: 8
    Last Post: 06-29-2011, 04:06 PM
  5. Currently logged in user into text box
    By ne16428 in forum Security
    Replies: 5
    Last Post: 06-10-2009, 11:46 AM

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