hi guys i have login form that the users will enter their username and password i saved the login information in access table called login, but when i try to login my system using correct username and password
the system crashes and visual basic 2005 display a message that say NullReference Exception was handled, i dont the cause of the problem can any one plz help


this my code

Option Explicit On
Public Class loginForm

    Dim rsLogin As ADODB.Recordset
    Dim iLoginFailure As Integer


    Private Sub Form_Initialize()

        Call Connection()
        rsLogin = New ADODB.Recordset

        With rsLogin
            
            .ActiveConnection = con

        End With

        iLoginFailure = 1    
    End Sub


    Private Sub txtUsername_Change()



        If txtUserName.Text = "" Then
            btnOK.Enabled = False
        Else
            btnOK.Enabled = True
        End If


    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If iLoginFailure <= 3 Then


            rsLogin.Open("Select * from login where username= " & txtUserName.Text & "", con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

            With rsLogin


                If .RecordCount = 0 Then

                    iLoginFailure = iLoginFailure + 1
                    MsgBox("Sorry! Invalid User Name! Please Try Again!", vbCritical, "Invalid Login!")

                    txtUserName.Text = ""


                End If

                If .RecordCount <> 0 Then
                    If txtPassword.Text = .Fields(6).Value Then

                        If .Fields(4) = "Administrator" Then



                            userName = .Fields(1).Value & " " & .Fields(2).Value
                            accessLevel = "Administrator"
                            userID = .Fields(0).Value
                            MAIN.Show()
                            Me.Hide()



                        ElseIf .Fields(4) = "Receptionist" Then

                            '
                            userName = .Fields(1).Value & " " & .Fields(2).Value
                            accessLevel = "Receptionist"
                            userID = .Fields(0).Value
                            MAIN.Show()
                            Me.Hide()

                        End If

                    Else


                        iLoginFailure = iLoginFailure + 1
                        MsgBox("Sorry! Invalid Password! Please Try Again!", vbCritical, "Invalid Login!")

                        txtPassword.Text = ""


                    End If

                End If

                .Close()

            End With

        Else

            MsgBox("Sorry! You Have To Login Within Three Tries! Unloading...", vbCritical, "Login Failure")
            End

        End If
    End Sub
End Class
This article has been dead for over six months. Start a new discussion instead.