Every module should have Option Explicit in header. This can be set to occur automatically when module is created. On the VBA editor menu: Tools > Options > Editor > Require variable declaration
The username is not filled in when user is required to change password. Subsequent logins work.
Form tblUser AllowAdditions property should be set to No. Password EnterKeyBehavior should be set to Default. Why would you allow new line in a password string? Also, only Password textbox should be editable. The other textboxes should be disabled.
On Login form change TabOrder of controls so textbox gets focus when form opens. I would not use Popup or Modal. SetFocus for textboxes is not working and haven't figured out why.
Suggest naming Command1 something more descriptive.
Consider:
Code:
Option Compare Database
Option Explicit
Private Sub Command1_Click()
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
ElseIf IsNull(DLookup("UserLogin", "tblUser", "UserLogin ='" & Me.TxtLoginID & "' And password = '" & Me.TxtPassword & "'")) Then
MsgBox "Incorrect LoginID or Password"
Else
ID = DLookup("UserID", "tblUser", "UserLogin = '" & Me.TxtLoginID.Value & "'")
UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.TxtLoginID & "'")
AccessLevel = DLookup("UserSecurity", "tblUser", "UserLogin = '" & Me.TxtLoginID & "'")
If Me.TxtPassword = "password" Then
MsgBox "Please Change Password", vbInformation, "New Password Required"
DoCmd.OpenForm "tblUser", , , "[UserID] =" & ID, , acDialog
End If
DoCmd.OpenForm "MAIN SCREEN"
Call Security(AccessLevel)
Forms![MAIN SCREEN]![TxtUser] = UserName
Forms![MAIN SCREEN]![txtsecurity] = AccessLevel
DoCmd.Close acForm, "Login", acSaveNo
End If
End Sub
Sub Security(UserSecurity As Integer)
Select Case UserSecurity
Case 1 'Admin
Case 2 'User
'me.AllowEdits = true
MsgBox "Your User Level Is 'User'"
Forms![MAIN SCREEN]!CmdAdmin.Enabled = False
End Select
End Sub
Code:
Option Compare Database
Option Explicit
Private Sub CmdSaveNPW_Click()
DoCmd.Close
End Sub
Private Sub Password_BeforeUpdate(Cancel As Integer)
If Me.Password = "password" Or Me.Password.OldValue = Me.Password Then
MsgBox "Invalid password."
Cancel = True
Me.Password = Null
End If
End Sub