joeserrone
The cat of the cul-de-sac
- Local time
- Today, 13:04
- Joined
- Dec 17, 2006
- Messages
- 164
I have the following code in a form to authenticate users based on their security level, this is based on a table called tblEmployees containing an autonumber as primary key, employee name and type of access. Once I authenticate the user I then open the appropriate form based on their access level. The new form that opens has the following code "on Load" cboNameEnter.Value = [Forms]![frmLogon]!cboEmployee. However the data brought in by this form is the Autonumber assigned to the employee, fieldname: lngEmpID. Since this is an older database that was contructed differently, I want the employee Name contained in the field called strEmpName visible in the appropriate form not the Autonumber assigned to the employee, fieldname: lngEmpID
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
Dim tmpaccess As String
tmpaccess = DLookup("strAccess", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
If tmpaccess = "Admin" Then
DoCmd.OpenForm "AdminWelcomeForm"
End If
If tmpaccess = "Power User" Then
DoCmd.OpenForm "PowerUserForm"
End If
If tmpaccess = "User" Then
DoCmd.OpenForm "UserForm"
End If
DoCmd.Close acForm, "frmLogon", acSaveNo
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen
Dim tmpaccess As String
tmpaccess = DLookup("strAccess", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
If tmpaccess = "Admin" Then
DoCmd.OpenForm "AdminWelcomeForm"
End If
If tmpaccess = "Power User" Then
DoCmd.OpenForm "PowerUserForm"
End If
If tmpaccess = "User" Then
DoCmd.OpenForm "UserForm"
End If
DoCmd.Close acForm, "frmLogon", acSaveNo
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub