Code:
Private Sub CmdLogin_Click()'/First thing needed is to decide which option to take
'/If there is an entry in the txtoldpwd field this is an existing password
'/If there is an entry in the txtconpwd field this is a new password setup
'/If there is an entry in all three then the user has reset their password
'/If password has been reset then all the validation has taken place
'/so can open the main menu straight away
Me.DepartmentName = Me.CboUser.Column(8)
DeptName = DLookup("[DepartmentName]", "tbl-Permissions", "CboUser = Forms!FrmLogin!CboUser")
If bReset = True Then
'/Open the main form and close this one
'DoCmd.OpenForm "FrmMain"
' MsgBox "You main form/ switchboard would be loaded here.", vbInformation + vbOKOnly, "End Of Demo"
Select Case Me.CboUser.Column(7)
Case 1
DoCmd.OpenForm "frmAdminMode"
Case 2
DeptName = DLookup("[DepartmentName]", "tbl-Permissions", "CboUser = Forms!FrmLogin!CboUser") 'This is where I want to pass the department to the new form
DoCmd.OpenForm "Copy Of frmUserDetailsInfo", acNormal, Me.CboUser.Column(8)
' DoCmd.OpenForm "Copy Of frmUserDetailsInfo"
'DoCmd.OpenForm "Copy of frmUserDetailsInfo", acNormal, , , , acWindowNormal
Case 3
DoCmd.OpenForm "frmSupervisors"
Case 4
DoCmd.OpenForm "frmReportsRequester"
End Select
Me.Visible = False
DoCmd.Close acForm, "FrmLogin"
Exit Sub
End If
If Trim(Me.TxtOldPWD & "") <> "" Then
'/does it match the users password
If Trim(Me.TxtOldPWD & "") <> DecryptKey(Me.CboUser.Column(4)) Then
'/No Match
MsgBox "The password you have entered cannot be recognised.", vbExclamation + vbOKOnly, "Invalid Password"
Me.TxtOldPWD = ""
Attempts = Attempts + 1
'/Three tries and your out
If Attempts = MaxAttempts Then
MsgBox "Maximum number of attempts has been reached", vbExclamation + vbOKOnly, "Login aborted"
DoCmd.Quit
Exit Sub
End If
Exit Sub
End If
'/Open the main form and close this one
' MsgBox "You main form/ switchboard would be loaded here.", vbInformation + vbOKOnly, "End Of Demo"
Select Case Me.CboUser.Column(7)
Case 1
DoCmd.OpenForm "frmAdminMode"
Case 2
Me.Filter = "[DepartmentName] = " & Forms!FrmLogin!CboUser.Column(8)
' DoCmd.OpenForm "Copy Of frmUserDetailsInfo", acNormal, Me.CboUser.Column(8)
DeptName = DLookup("[DepartmentName]", "tbl-Permissions", "CboUser = Forms!FrmLogin!CboUser")
DoCmd.OpenForm "Copy Of frmUserDetailsInfo"
Case 3
DoCmd.OpenForm "frmSupervisors"
Case 4
DoCmd.OpenForm "frmReportsRequester"
End Select
DoCmd.Close acForm, "FrmLogin"
Else
'/Has the user go a password
If DecryptKey(Me.CboUser.Column(4)) <> "Not Set" Then
MsgBox "You must enter you password first", vbExclamation + vbOKOnly, "Mandatory Requirement"
Attempts = Attempts + 1
'/three tries and your out.
If Attempts = MaxAttempts Then
MsgBox "Maximum number of attempts has been reached", vbExclamation + vbOKOnly, "Login aborted"
DoCmd.Quit
Exit Sub
Else
Exit Sub
End If
End If
'/New password setup
'/Compare both both entries as matching
'/Is there an entry in either of the text boxes
If Trim(Me.TxtNewPWD & "") = "" Then
MsgBox "You must enter a new password. Cannot be left blank.", vbExclamation + vbOKOnly, "Invalid Password"
Exit Sub
End If
If Trim(Me.TxtConPWD & "") = "" Then
MsgBox "You must confirm the new password. Cannot be left blank.", vbExclamation + vbOKOnly, "Invalid Password Confirmation"
Exit Sub
End If
'/do they match
If Trim(Me.TxtNewPWD & "") <> Trim(Me.TxtConPWD & "") Then
MsgBox "Passwords do not match.", vbExclamation + vbOKOnly, "Invalid Password Confirmation"
Me.TxtConPWD.SetFocus
Exit Sub
Else
'/they both match so we can add this new password to the users record
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select * From [Tbl-Permissions] Where FKUserID=" & Me.CboUser.Column(0))
If Not rs.EOF And Not rs.BOF Then
rs.Edit
rs("LoginName") = StrUserName
rs("PWD") = EncryptKey(Me.TxtConPWD)
rs("fldDatePWD") = Date
rs.Update
rs.Close
End If
Set rs = Nothing
MsgBox "You password has been set", vbInformation + vbOKOnly, "New Password"
'/Open the main form and close this one
'MsgBox "You main form/ switchboard would be loaded here.", vbInformation + vbOKOnly, "End Of Demo"
Select Case Me.CboUser.Column(7)
Case 1
DoCmd.OpenForm "frmAdminMode"
Case 2
' Me.Filter = "[DepartmentName] = " & Forms!FrmLogin!CboUser.Column(8)
'DoCmd.OpenForm "Copy Of frmUserDetailsInfo", acNormal, Me.CboUser.Column(8)
DeptName = DLookup("[DepartmentName]", "tbl-Permissions", "CboUser = Forms!FrmLogin!CboUser")
DoCmd.OpenForm "Copy Of frmUserDetailsInfo"
Case 3
DoCmd.OpenForm "frmSupervisors"
Case 4
DoCmd.OpenForm "frmReportsRequester"
End Select
'DoCmd.OpenForm "FrmMain"
DoCmd.Close acForm, "FrmLogin"
End If
End If
' Me.Filter = "[DepartmentName] = " & Forms!FrmLogin!CboUser.Column(8)
End Sub
'"Copy of frmUserDetails Query in SQL view
SELECT UserDetails.StaffName, UserDetails.*, UserDetails.DepartmentName
FROM UserDetails
WHERE (((UserDetails.DepartmentName)=[Forms]![FrmLogin]![DepartmentName]))
ORDER BY UserDetails.StaffName;