I am making a login system that records time in and time out for students..
but the student can't sign in if already "Signed In" and student can't sign Out if already "signed out"
that is why i have three form.

**THE CONCEPT OF THE PROGRAM: When i log in as student. it goes to frmStudentIn and then return to main form.. after that
when I reloged in again. the program determines that i already logged in and goes to frmStudentOut. **

WHAT IS HAPPENING (PROBLEM): When i log in as student. it goes to frmStudentIn and then return to main form.. after that when I reloged in again. the program still enter frmLogin instead of frmStudentOut. But when I close the program that's the only time it enter the frmStudentOut

These are my codes.

frmMain
Imports System.Data.OleDb

Public Class frmMain

Dim ds As New DataSet
Dim adptr As OleDbDataAdapter
Dim connectionString As String
Dim attempt As Integer = 1
Private Sub btnSign_Click(sender As Object, e As EventArgs) Handles btnSign.Click

    connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb"
    Dim sql As String
    Sql = "Select ID, PASSWORD, LASTNAME, FIRSTNAME, LOGINSTATUS from Users"
    Dim cnn = New OleDbConnection(connectionString)
    Try
        cnn.Open()
        adptr = New OleDbDataAdapter(sql, cnn)
        adptr.Fill(ds)
        'check if username and password is matched'
        If ds.Tables(0).Rows(0).Item(0) = txtID.Text Then
            MessageBox.Show("Username Matched")
            If ds.Tables(0).Rows(0).Item(1) = txtPassword.Text Then
                MessageBox.Show("Password Matched")
                'check if admin'
                If ds.Tables(0).Rows(0).Item(4) = "Admin" Then
                    MessageBox.Show("You are now Logged In as Admin.")
                    frmFaculty.Show()
                    Me.Hide()
                Else 'fill student information'
                    MessageBox.Show("You are now Logged In.")
                    frmStudentOut.lblSI.Text = ds.Tables(0).Rows(0).Item(0)
                    frmStudentOut.lblLN.Text = ds.Tables(0).Rows(0).Item(2)
                    frmStudentOut.lblFN.Text = ds.Tables(0).Rows(0).Item(3)
                    frmStudentOut.lblLS.Text = ds.Tables(0).Rows(0).Item(4)
                    frmStudentIn.lblSI.Text = ds.Tables(0).Rows(0).Item(0)
                    frmStudentIn.lblLN.Text = ds.Tables(0).Rows(0).Item(2)
                    frmStudentIn.lblFN.Text = ds.Tables(0).Rows(0).Item(3)
                    frmStudentIn.lblLS.Text = ds.Tables(0).Rows(0).Item(4)
                    'check if already signed in or not'
                    If ds.Tables(0).Rows(0).Item(4) = "Signed In" Then
                        Me.Hide()
                        frmStudentOut.Show()
                    ElseIf ds.Tables(0).Rows(0).Item(4) = "Signed Out" Then
                        Me.Hide()
                        frmStudentIn.Show()
                    End If
                End If
            Else
                MessageBox.Show("Wrong Password!")
                MessageBox.Show("Please Try Again." & vbNewLine & "ATTEMPT: " & attempt & " out of 3")
                attempt = attempt + 1
                txtID.Text = String.Empty
                txtPassword.Text = String.Empty

            End If
        Else
            MessageBox.Show("Username cannot find!")
            MessageBox.Show("Please Try Again." & vbNewLine & "ATTEMPT: " & attempt & " out of 3")
            attempt = attempt + 1
            txtID.Text = String.Empty
            txtPassword.Text = String.Empty
        End If
        adptr.Dispose()
    Catch ex As Exception
    End Try
    cnn.Close()
    'log-in attempt 3x fail'
    If attempt > 3 Then
        MessageBox.Show("You have exceeded the number of login attempt." & vbNewLine & "Please Contact the Administrator.")
        attempt = 1
    End If
End Sub

Imports System.Data.OleDb

frmStudentIn

Public Class frmStudentIn

Private Sub loginBTN_Click(sender As Object, e As EventArgs) Handles loginBTN.Click

    Dim Command3 As New OleDbCommand
    Dim Command4 As New OleDbCommand
    Dim i1 As Integer
    Dim u1 As Integer
    Dim sql2 As String
    Dim sql4 As String
    Try
        Dim cnn2 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb;")
        cnn2.Open()
        sql2 = "INSERT INTO Audit ([ID],[LASTNAME],[FIRSTNAME],[TIMEIN]) VALUES('" & lblSI.Text & "','" & lblLN.Text & "','" & lblFN.Text & "','" & DateTime.Now & "')"
        sql4 = "UPDATE Users SET LOGINSTATUS = 'Signed In'  WHERE ID = '" & lblSI.Text & "'"
        Command3 = New OleDbCommand(sql2, cnn2)
        Command4 = New OleDbCommand(sql4, cnn2)
        i1 = Command3.ExecuteNonQuery
        u1 = Command4.ExecuteNonQuery
    Catch ex As Exception

    End Try
    MessageBox.Show("You have successfully Signed in." & vbNewLine & " Please Don't Forget to Logout.")
    Me.Close()
    frmMain.Show()
    frmMain.txtID.Text = String.Empty
    frmMain.txtPassword.Text = String.Empty
End Sub

End Class

frmStudentOut

Imports System.Data.OleDb

Public Class frmStudentOut

Private Sub logoutBTN_Click(sender As Object, e As EventArgs) Handles logoutBTN.Click
    Dim Command1 As New OleDbCommand
    Dim Command2 As New OleDbCommand
    Dim i2 As Integer
    Dim u2 As Integer
    Dim sql3 As String
    Dim sql5 As String
    Try
        Dim cnn3 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Renz\Documents\Visual Studio 2012\FINAL\Database\AuditDB.mdb;")
        cnn3.Open()
        sql3 = "INSERT INTO Audit ([ID],[LASTNAME],[FIRSTNAME],[TIMEOUT]) VALUES('" & lblSI.Text & "','" & lblLN.Text & "','" & lblFN.Text & "','" & DateTime.Now & "')"
        sql5 = "UPDATE Users SET LOGINSTATUS = 'Signed Out'  WHERE ID = '" & lblSI.Text & "'"
        Command1 = New OleDbCommand(sql3, cnn3)
        Command2 = New OleDbCommand(sql5, cnn3)
        i2 = Command1.ExecuteNonQuery
        u2 = Command2.ExecuteNonQuery
    Catch ex As Exception

    End Try
    MessageBox.Show("You have successfully Signed Out.")
    Me.Close()
    frmMain.Show()
    frmMain.txtID.Text = String.Empty
    frmMain.txtPassword.Text = String.Empty
End Sub

End Class

you have to send the project so we can test it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.