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