Hello, my problem is that on my DB I have a user login screen. This screen has a checkbox which allows the user to remember their credentials on their current computer. The problem I have is that the only way I knew to do this was to use the following code:
This section is in the On Open event for the login screen-
Code:
Private Sub Form_Open(Cancel As Integer)Dim User1 As String
Dim User2 As String
Dim User3 As String
Dim User4 As String
On Error GoTo Err_Bellingham
User1 = Nz(DLookup("empRemLocat", "tblLogin", "[empID] = 1300"), "")
User2 = Nz(DLookup("empRemLocat", "tblLogin", "[empID] = 1296"), "")
User3 = Nz(DLookup("empRemLocat", "tblLogin", "[empID] = 1309"), "")
User4 = Nz(DLookup("empRemLocat", "tblLogin", "[empID] = 1198"), "")
'1************************
If User1 = Environ("ComputerName") Then
If "1" = DLookup("empRemember", "tblLogin", "[EmpID] = 1300") Then
Me.cboEmployee.Value = "1300"
Me.chkRememberMe = True
Me.txtPassword.Value = DLookup("empPwd", "tblLogin", "[EmpID] =" & Me.cboEmployee.Value)
Else
Me.cboEmployee.SetFocus
Me.chkRememberMe = False
Me.chkRememberMe.DefaultValue = False
intLogonAttempts = 0
Exit Sub
End If
'2************************
ElseIf Environ("ComputerName") = User2 Then
If "1" = DLookup("empRemember", "tblLogin", "[EmpID] = 1296") Then
Me.cboEmployee.Value = "1296"
Me.chkRememberMe = True
Me.txtPassword.Value = DLookup("empPwd", "tblLogin", "[EmpID] =" & Me.cboEmployee.Value)
Else
Me.cboEmployee.SetFocus
Me.chkRememberMe = False
Me.chkRememberMe.DefaultValue = False
intLogonAttempts = 0
Exit Sub
End If
'3************************
ElseIf Environ("ComputerName") = User3 Then
If "1" = DLookup("empRemember", "tblLogin", "[EmpID] = 1309") Then
Me.cboEmployee.Value = "1309"
Me.chkRememberMe = True
Me.txtPassword.Value = DLookup("empPwd", "tblLogin", "[EmpID] =" & Me.cboEmployee.Value)
Else
Me.cboEmployee.SetFocus
Me.chkRememberMe = False
Me.chkRememberMe.DefaultValue = False
intLogonAttempts = 0
Exit Sub
End If
'4************************
ElseIf Environ("ComputerName") = User4 Then
If "1" = DLookup("empRemember", "tblLogin", "[EmpID] = 1198") Then
Me.cboEmployee.Value = "1198"
Me.chkRememberMe = True
Me.txtPassword.Value = DLookup("empPwd", "tblLogin", "[EmpID] =" & Me.cboEmployee.Value)
Else
Me.cboEmployee.SetFocus
Me.chkRememberMe = False
Me.chkRememberMe.DefaultValue = False
intLogonAttempts = 0
Exit Sub
End If
End If
'5************************
Me.cboEmployee.SetFocus
intLogonAttempts = 0
Call UserClockIn
DoCmd.OpenForm "frmLogoutTimer", , , , , acHidden
'6************************
Exit_Bellingham:
Exit Sub
Err_Bellingham:
MsgBox Err.Description, vbCritical, "ERROR!"
Call LogError(Err.Number, Err.Description, "Bellingham()")
Resume Exit_Bellingham
End Sub
This section is in the on click event for the login button-
Code:
If Me.chkRememberMe.Value = False Then Set rst = CurrentDb.OpenRecordset("tblLogin", dbOpenDynaset)
rst.FindFirst "EmpID =" & Me.cboEmployee.Value
rst.Edit
rst![empRemember] = "-1"
rst![empRemLocat] = "Not Remembered"
rst.Update
rst.Close
Else
Set rst = CurrentDb.OpenRecordset("tblLogin", dbOpenDynaset)
rst.FindFirst "EmpID =" & Me.cboEmployee.Value
rst.Edit
rst![empRemember] = "1"
rst![empRemLocat] = Environ("ComputerName")
rst.Update
rst.Close
End If
As you can see this will work...but only because I put the user information in the code, and this was only possible because when originally developed there was only going to be 4 people with access to this DB....now there is going to be about 50-75 and I do not know a better way to do this. My initial guess is that i need to use some type of recordset loop, but I have never done anything with looping and only the bare minimum with record sets. Any tips or hints in the right direction will be immensely appreciated.