Results 1 to 5 of 5
  1. #1
    nika.duncan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    36

    Password validation not working


    Hi All,
    I have a login form that is linked to three other forms - Manager, Supervisors, Staff and Admin. I uses a table with Access Level 1-4 and base on whichever level it opens the form. The problem I am having is that the if I enter an incorrect password it still opens the correct form. the code I've use is not checking the password, not sure where to correct. Please if anyone can assist I have attached the code below. This will be greatly appreciated.
    Code:
    Private Sub txtPassword_AfterUpdate()
    
    Me.txtAccessLevel = Me.cboLogin.Column(3)
    Me.txtPassword = Me.cboLogin.Column(1)
    
    
    'Check that a user has been selected
    If IsNull(Me.cboLogin) Then
        MsgBox "You need to select a user!", vbCritical
        Me.cboLogin.SetFocus
    
    
    Else
       ' Check for correct password
       If Me.txtPassword = Me.cboLogin.Column(1) Then
            'Check if password needs to be reset
           ' If Me.cboLogin.Column(2) = True Then
           ' DoCmd.OpenForm "frmPasswordChange", , , "[UserLoginID] = " & Me.cboLogin
           ' DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            'Else
                
                If Me.txtAccessLevel = 1 Then
                DoCmd.OpenForm "frmAdminMode"
                Me.Visible = False
                Else
    
    
                    If Me.txtAccessLevel = 2 Then
                        DoCmd.OpenForm "frmManagers"
                        Me.Visible = False
                    Else
    
    
                        If Me.txtAccessLevel = 3 Then
                            DoCmd.OpenForm "frmSupervisors"
                            Me.Visible = False
                        Else
    
    
                            If Me.txtAccessLevel = 4 Then
                                DoCmd.OpenForm "frmStaff"
                                Me.Visible = False
                            Else
    
    
                                MsgBox "Password does not match, please re-enter!", vboOkOnly
                                Me.txtPassword = Null
                                Me.txtPassword.SetFocus
                            End If
                       End If
                    End If
              End If
    
    
      End If
    
    
      End If
     ' End If
    
    
    
    
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You set the value and then test it against the same thing it was set to, so it will always match.

    Me.txtPassword = Me.cboLogin.Column(1)


    If Me.txtPassword = Me.cboLogin.Column(1) Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    nika.duncan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    36
    Thanks for the input and I have change the code to read "If Me.txtPassword <> Me.cboLogin.Column(1) Then" base on explanation but it still doesn't perform the check it just goes through and opens the form no matter what password has been entered. I am not sure what to do to perform the check. Please help.



    Code:
    Private Sub txtPassword_AfterUpdate()
    
    Me.txtAccessLevel = Me.cboLogin.Column(3)
    Me.txtPassword = Me.cboLogin.Column(1)
    
    
    'Check that a user has been selected
    If IsNull(Me.cboLogin) Then
        MsgBox "You need to select a user!", vbCritical
        Me.cboLogin.SetFocus
        
    Exit Sub
    End If
    
    
       
       ' Check for correct password
       If Me.txtPassword <> Me.cboLogin.Column(1) Then
            MsgBox "Password does not match, please re-enter!", vbOKOnly
            Me.txtPassword = Null
            Me.txtPassword.SetFocus
    Exit Sub
        End If
        
            
            'Check if password needs to be reset
           ' If Me.cboLogin.Column(2) = True Then
           ' DoCmd.OpenForm "frmPasswordChange", , , "[UserLoginID] = " & Me.cboLogin
           ' DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            'Else
                
                If Me.txtAccessLevel = 1 Then
                DoCmd.OpenForm "frmAdminMode"
                Me.Visible = False
             Exit Sub
             End If
             
    
    
                    If Me.txtAccessLevel = 2 Then
                        DoCmd.OpenForm "frmManagers"
                        Me.Visible = False
             Exit Sub
             End If
             
             '       Else
    
    
                        If Me.txtAccessLevel = 3 Then
                            DoCmd.OpenForm "frmSupervisors"
                            Me.Visible = False
              Exit Sub
              End If
              
              '          Else
    
    
                            If Me.txtAccessLevel = 4 Then
                                DoCmd.OpenForm "frmStaff"
                                Me.Visible = False
                Exit Sub
                End If
                
    'Else
    
    
    '                            MsgBox "Password does not match, please re-enter!", vboOkOnly
    '                            Me.txtPassword = Null
    '                            Me.txtPassword.SetFocus
                            
                    
    
    
    
    
    End Sub

  4. #4
    nika.duncan is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    36
    Thanks for pointing me in the right direction I was able to get it working with the code below.

    Code:
    Private Sub txtPassword_AfterUpdate()
    
    Me.txtAccessLevel = Me.cboLogin.Column(3)
    
    
    
    
    'Check that a user has been selected
    If IsNull(Me.cboLogin) Then
        MsgBox "You need to select a user!", vbCritical
        Me.cboLogin.SetFocus
        
    Exit Sub
    End If
    
    
       
       ' Check for correct password
       If Me.txtPassword <> Me.UserPassword Then
            MsgBox "Password does not match, please re-enter!", vbOKOnly
            Me.txtPassword = Null
            Me.txtPassword.SetFocus
    Exit Sub
        End If
        
            
            'Check if password needs to be reset
           ' If Me.cboLogin.Column(2) = True Then
           ' DoCmd.OpenForm "frmPasswordChange", , , "[UserLoginID] = " & Me.cboLogin
           ' DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            'Else
                
                If Me.txtAccessLevel = 1 Then
                DoCmd.OpenForm "frmAdminMode"
                Me.Visible = False
             Exit Sub
             End If
             
    
    
                    If Me.txtAccessLevel = 2 Then
                        DoCmd.OpenForm "frmManagers"
                        Me.Visible = False
             Exit Sub
             End If
             
             '       Else
    
    
                        If Me.txtAccessLevel = 3 Then
                            DoCmd.OpenForm "frmSupervisors"
                            Me.Visible = False
              Exit Sub
              End If
              
              '          Else
    
    
                            If Me.txtAccessLevel = 4 Then
                                DoCmd.OpenForm "frmStaff"
                                Me.Visible = False
                Exit Sub
                End If
                
    'Else
    
    
    '                            MsgBox "Password does not match, please re-enter!", vboOkOnly
    '                            Me.txtPassword = Null
    '                            Me.txtPassword.SetFocus
                            
                    
    
    
    
    
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. MS Access password filed validation
    By mithu 1992 in forum Access
    Replies: 1
    Last Post: 09-24-2013, 08:21 AM
  2. Validation Rule Not Working??
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 12-23-2011, 02:22 PM
  3. Change Password field in Table not working
    By bongazi in forum Programming
    Replies: 4
    Last Post: 05-18-2011, 04:33 PM
  4. Login/Password Code not working
    By eww in forum Programming
    Replies: 3
    Last Post: 09-21-2010, 10:49 AM
  5. password validation
    By RycherX in forum Forms
    Replies: 1
    Last Post: 02-20-2010, 03:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums