by the way. this is now my problem.

THIS IS FOR TIME IN...

Private Sub cmdIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdIN.Click
        lblempno.Text = txtempno.Text
        lblIN.Text = lbltime.Text & lbldate.Text
        MsgBox("Log in successful!", vbInformation)
        lv = ListView1.Items.Add(lbltime.Text)
        txtempno.Text = ""
        txtempno.Focus()

    End Sub

THIS IS FOR TIME OUT...

Private Sub cmdOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOut.Click
        If lblIN.Text = "" Then
            MsgBox("Failed to save Log in first.")
            txtempno.Text = ""
            txtempno.Focus()
            Exit Sub
        End If
        If txtempno.Text = "" Then
            MsgBox("Please put your employee number", vbExclamation)
            txtempno.Focus()
            Exit Sub
        End If

        Try
            lblOUT.Text = lbltime.Text & lbldate.Text
            con2.Open()
            Dim cmd As New SqlCeCommand("insert into tbl_timerec(EmpNo, TimeIN, TimeOUT) VALUES('" & lblempno.Text & "','" & lblIN.Text & "','" & lblOUT.Text & "')", con2)
            dr = cmd.ExecuteReader
            dr.Read()
            MsgBox("Log out sucessful!", vbInformation)

            lv.SubItems.Add(lbltime.Text)

            con2.Close()

            lblIN.Text = ""
            lblOUT.Text = ""
            lblempno.Text = ""
            txtempno.Text = ""
            txtempno.Focus()
        Catch ex As Exception
            MsgBox("[ERROR]" & ex.Message)
            txtempno.Text = ""
            txtempno.Focus()
        End Try
    End Sub

E.G:
if the user1 time in and the user2 will time too, [hours later] if the user1 will use the time out it will go to the last row [last row is user2].

so i want is if the user1 will use the time out using his Employee number it will go to the row the when he time in.

If I understand your problem, you have a listview ini details view. Each row contains a login/logout time and an employee number. A row gets added when a user logs in and, when the user logs out, you want to update that row with the logout time. Is that correct?

If that is the case then you just need to scan the listview items and look for the first entry for that employee number that has no value entered for logout. You have to check for a blank entry ini case that employee has logged in and out already.

Lets assume you have a listview with three columns. Column 1 contains the employee ID, column 2 the login time and column 3 the logout time. Let's say that employee "4096" has just logged out and you want to update the correct record. You do

For Each item As ListViewItem In ListView1.Items
    If item.Text = "4096" And item.SubItems(2).Text = "" Then
        item.SubItems(2).Text = Now().ToString("HH:mm:ss")
    End If
Next

If I understand your problem, you have a listview ini details view. Each row contains a login/logout time and an employee number. A row gets added when a user logs in and, when the user logs out, you want to update that row with the logout time. Is that correct?

If that is the case then you just need to scan the listview items and look for the first entry for that employee number that has no value entered for logout. You have to check for a blank entry ini case that employee has logged in and out already.

Lets assume you have a listview with three columns. Column 1 contains the employee ID, column 2 the login time and column 3 the logout time. Let's say that employee "4096" has just logged out and you want to update the correct record. You do

For Each item As ListViewItem In ListView1.Items
    If item.Text = "4096" And item.SubItems(2).Text = "" Then
        item.SubItems(2).Text = Now().ToString("HH:mm:ss")
    End If
Next

invalid argument = value of '2' is not valid for 'index' parameter name index

I can't tell you what that means without seeing the code and the specific line that generated the error.

I can't tell you what that means without seeing the code and the specific line that generated the error.

i have index of 0,1,2

0 = emp number
1 = time in
2 = time out

so whats the problem?

Read my previous post again

I can't tell you what that means without seeing the code and the specific line that generated the error.

For Each item As ListViewItem In ListView1.Items
                If item.Text = txtempno.Text And item.SubItems(2).Text = "OUT" Then
                    item.SubItems.Add(2).Text = lbltime.Text
                End If
            Next

that's my code now. the problem now is it didn't add.

Why are you comparing

item.SubItems(2).Text = "OUT"

If the user has not logged out then this field should be empty. Try

item.SubItems(2).Text = ""

nothings work. it didn't add in the list view. i already double checked it.

my msgbox says it is successful but it didn't add in the list view.

THIS IS FOR TIME OUT...

Private Sub cmdOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOut.Click
        If lblIN.Text = "" Then
            MsgBox("Failed to save Log in first.")
            txtempno.Text = ""
            txtempno.Focus()
            Exit Sub
        End If
        If txtempno.Text = "" Then
            MsgBox("Please put your employee number", vbExclamation)
            txtempno.Focus()
            Exit Sub
        End If

        Try
            lblOUT.Text = lbltime.Text & lbldate.Text
            con2.Open()
            Dim cmd As New SqlCeCommand("insert into tbl_timerec(Name, TimeIN, TimeOUT) VALUES('" & lblempno.Text & "','" & lblIN.Text & "','" & lblOUT.Text & "')", con2)
            dr = cmd.ExecuteReader
            dr.Read()
            MsgBox("Log out sucessful!", vbInformation)

            For Each item As ListViewItem In ListView1.Items
                If item.Text = lblempno.Text And item.SubItems(2).Text = "" Then
                    item.SubItems.Add(2).Text = lbltime.Text
                End If
            Next
            con2.Close()

            lblIN.Text = ""
            lblOUT.Text = ""
            lblempno.Text = ""
            txtempno.Text = ""
            txtempno.Focus()
        Catch ex As Exception
            MsgBox("[ERROR]" & ex.Message)
            txtempno.Text = ""
            txtempno.Focus()
        End Try
    End Sub

THIS IS FOR TIME IN...

Private Sub cmdIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdIN.Click
        Dim dtchkempno As DataTable
        dtchkempno = empchk(txtempno.Text)

        If txtempno.Text = "" Then
            MsgBox("Please put your employee number to log in.")
            Exit Sub
        End If

        If dtchkempno.Rows.Count = 0 Then
            MsgBox("The Employee number is not on the database", vbExclamation)
            txtempno.Text = ""
            txtempno.Focus()
            Exit Sub
        End If

        lblempno.Text = txtempno.Text
        lblIN.Text = lbltime.Text & lbldate.Text
        MsgBox("Log in successful!", vbInformation)
        lv = ListView1.Items.Add(lbltime.Text)
        lv.SubItems.Add(lblOUT.Text)
        lv.SubItems.Add(lblempno.Text)

        txtempno.Text = ""

        txtempno.Focus()

    End Sub

this is now my code.

Please answer. :sad:

For TIME_IN, replace line 21 with

lv.SubItems.Add(lblOUT.Text)

For TIME_OUT replace lines 22-26 with

For Each item As ListViewItem In ListView1.Items
    If item.SubItems(2) = lblempno.Text And item.SubItems(1).Text = "" Then
        item.SubItems.Add(1).Text = lbltime.Text
    End If
Next

The problem was that in my example, the columns were empid,in,out and in yours they are in,out,empid.

I took a while to answer but a guy's gotta sleep sometime ;)

item.SubItems(2) = lblempno.Text

why der is a blue line in that code? it says..

Overload resolution failed because no accessible '=' can be called with these arguments:

i already tried

items.subitems(2).tostring/text

not working at all..

Sorry. That should have been

item.SubItems(2).Text

see what happens when I don't get my sleep?

oh wait how can i edit my past post?

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.