Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

Microsoft Access - setting up a login

Good afternoon - using some code I found online, I generated a login for an MS Access database I'm working on.

tblEmployees has another field - strAccess. The code below works, but doesn't check this field. It brings you to frmAdminNavigation. Ideally, once the password is verified, I need to run a check on strAccess. If it's an admin, it goes to one form (frmAdminNavigation). If its a user, it goes to another (frmUserNavigation).

I'll paste my code here for review. Thanks!

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

        lngMyEmpID = Me.cboEmployee.Value
       
   

'Close logon form and open splash screen
       
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "frmAdminNavigation"

        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    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
0
anglandp
Asked:
anglandp
1 Solution
 
Rey Obrero (Capricorn1)Commented:
'Check value of password in tblEmployees to see if this matches value chosen in combo box

'if values admin and user are stored in table tblEmployees, use a dlookup to get strAccess

    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee.Value
       
       strAccess=dlookup("AccessFieldName", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)


'change "AccessFieldName" with the actual name of the field for access


'Close logon form and open splash screen
       
        DoCmd.Close acForm, "frmLogon", acSaveNo

if straccess="admin" then
        DoCmd.OpenForm "frmAdminNavigation"
    else
        DoCmd.OpenForm "frmUserNavigation"
end if




        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now