Authentication problem

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
 
The field you are dealing with appears to be a combo box. The autonumber field is what is bound to that field, and the name appears in the visible box because that is what the combo box is designed to do. More than likely, the number is the first field and the name is the second field in the combo box RowSource query. Look for Bound Column in the Data tab properties for the cboEmployee field on your login form. I assume it will be a 1. Then look at the Column Count property under the Format tab. I assume it will be two. Then the Column Widths property should start with a 0. All this is how I assume the combo box is already set up. If so, then rather than just specifiying the combo box to get the employee name, you will need to refer to the correct column that holds the employee name. Again, I'm going to assume that it is the second column, and because Access starts counting at 0, to get the second column we refer to it as .Column(1). So, if all my assumptions are correct, you need code simular to this:
Code:
MyNewColumnForEmployeeName = Forms!frmLogin!cboEmployee.Column(1)
Hope you can follow all that. If not, look up columns and combo boxes as a resource for more help.
 
Makes Perfect Sense now!!! Thanks for all your help!!!

Joe
 

Users who are viewing this thread

Back
Top Bottom