• login form

    Author
    Topic
    #1772917

    I’m currently supporting ms access db that was design by someone else. Although there is a form for users to input their credentials (username/password) I recently noticed by just clicking logon button (without entering credentials) one can access the db.

    Below is the code used:

    Code:
    Private Sub txtUserNm_AfterUpdate()’User validation
    Dim db As DAO.Database
    Dim rstUser As DAO.Recordset
    Dim strUserNm As String
    
    
    ‘Set db = CurrentDb     
    Set db = OpenDatabase(“S:DB Foldername of DB”)
    Set rstUser = db.OpenRecordset(“tblLOGIN”)
    strUserNm = Me.txtUserNm
    gblUserNm = Me.txtUserNm
    rstUser.Index = “USERNM”
    rstUser.Seek “=”, strUserNm
    If rstUser.NoMatch = False Then
        Me.txtPWD.Enabled = True
        Me.txtPWD.SetFocus
        Me.txtValidUser = “Y”
    Else
        MsgBox “No Match For User Name ” & strUserNm, vbInformation + vbOKOnly, “INVALID USER NAME”
        Me.txtAttempts = Me.txtAttempts + 1
        If Me.txtAttempts = 3 Then
            MsgBox “Check User Name And Try Again” & vbCrLf & ”          GOOD-BYE”, vbCritical + vbOKOnly, “TRY AGAIN LATER”
            DoCmd.Close
        Else
            Me.txtUserNm = Null
            Me.txtUserNm.SetFocus
        End If
    End If
    
    
    End Sub
    
    
    Private Sub txtUserNm_BeforeUpdate(Cancel As Integer)
    ‘Check To See If User Are Valid. Look Into The Table To Get User Status
    Dim strUser As String
    Dim strStatus As String
    Dim strSQL As String
    Dim db As DAO.Database
    Dim rstStatus As DAO.Recordset
    
    
    Set db = OpenDatabase (“S:DB Foldername of DB”) 
    Set rstStatus = db.OpenRecordset(“tblLOGIN”)
    strUser = Me.txtUserNm
    rstStatus.Index = “USERNM”
    rstStatus.Seek “=”, strUser
    
    
    If rstStatus!STATUS = “A” Then
        strStatus = rstStatus!STATUS
        Me.txtStatus = strStatus
    End If
    
    
        If Me.txtStatus = “A” Then
            Me.txtPWD.Enabled = True
         ‘  Me.txtPWD.SetFocus
            Me.txtValidUser = “Y”
        Else
            MsgBox “Invalid User Name Try Again” & vbCrLf & ”          GOOD-BYE”, vbCritical + vbOKOnly, “TRY AGAIN LATER”
            Me.txtValidUser = “N”
            Me.txtPWD.Enabled = False
            Me.cmdLOGIN.Enabled = False
            DoCmd.Quit
        End If
    End Sub
    
    
    Private Sub txtUserNm_GotFocus()
    ‘Check Users Information If Valid Then Set Focus To Password Otherwise Close
        If Me.txtValidUser = “Y” And Me.txtInvalidPW = “Y” Then
            Me.txtPWD.SetFocus
        End If
        
    End Sub
    
    
    

    Can you please assist in identifying the problem?

    TIA

    Reply To: login form

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: