THIS CODE IS WORKING,, BUT WHEN THE SECOND TIME LOGGING IN IT DOUBLE CHECKED LIKE 2 FORMS OPEN and 4 MESSAGE BOX APPEAR
Private Sub btnSign_Click(sender As Object, e As EventArgs) Handles btnSign.Click
Dim connectionString As String
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb"
sql = "Select ID, LASTNAME, FIRSTNAME, LOGINSTATUS from Users"
cnn = New OleDbConnection(connectionString)
Try
cnn.Open()
adptr = New OleDbDataAdapter(sql, cnn)
adptr.Fill(ds)
For i = 0 To ds.Tables(0).Rows.Count - 1
'check if username and password is matched'
If ds.Tables(0).Rows(i).Item(0) = txtID.Text Then
MessageBox.Show("UserName Matched")
If ds.Tables(0).Rows(i).Item(1) = txtPassword.Text Then
MessageBox.Show("Password Matched")
'check if admin'
If txtPassword.Text = "admin" Then
MessageBox.Show("You are now Logged In as Admin.")
frmFaculty.Show()
Me.Hide()
Else 'fill student information'
frmStudentIn.lblSI.Text = ds.Tables(0).Rows(i).Item(0)
frmStudentIn.lblLN.Text = ds.Tables(0).Rows(i).Item(1)
frmStudentIn.lblFN.Text = ds.Tables(0).Rows(i).Item(2)
frmStudentIn.lblLS.Text = ds.Tables(0).Rows(i).Item(3)
frmStudentOut.lblSI.Text = ds.Tables(0).Rows(i).Item(0)
frmStudentOut.lblLN.Text = ds.Tables(0).Rows(i).Item(1)
frmStudentOut.lblFN.Text = ds.Tables(0).Rows(i).Item(2)
frmStudentOut.lblLS.Text = ds.Tables(0).Rows(i).Item(3)
MessageBox.Show("You are now Logged In.")
'check if already signed in or not'
If ds.Tables(0).Rows(i).Item(3) = "Logged In" Then
frmStudentOut.Show()
Me.Hide()
Else
frmStudentIn.Show()
Me.Hide()
End If
End If
Else
MessageBox.Show("Invalid Password.")
MessageBox.Show("Please Try Again." & vbNewLine & "ATTEMPT: " & attempt & " out of 3")
attempt = attempt + 1
End If
End If
Next
cnn.Close()
Catch ex As Exception
End Try
'log-in attempt 3x fail'
If attempt > 3 Then
MessageBox.Show("You have exceeded the number of login attempt." & vbNewLine & "Please Contact the Administrator.")
End If
End Sub