0

Delete checked item (one or more) from listview I write this code.

  Dim x As Long
                For x = LVEmp.ListItems.Count To 1 Step -1
            If LVEmp.ListItems(x).Checked Then
                con.Execute "DELETE FROM stock WHERE [SrNo] = '" & LVEmp.ListItems(x).SubItems(1) & "'"

                LVEmp.ListItems.Remove x
            End If
        Next

        con.Close
        Set con = Nothing

but it show error massage:
run time error -2147217913 (80040e07)
data type mismatch in criteria expression.

3
Contributors
4
Replies
21
Views
11 Months
Discussion Span
Last Post by Shark_1
0

It looks to me that the query is loking to compare numbers but you're giving it a string. Try converting the subitem value to a number and calling the query with that.

0

LVEmp.ListItems.Remove x
here x should be an object not a numerical value which is ListItem or Item.

For x = LVEmp.ListItems.Count To 1 Step -1
and also the loop should be

    For x = (LVEmp.ListItems.Count-1) To 0 Step -1

Edited by Shark_1

0

In database it was numeric. so what problem?

How would you call an object by a numerical value ?
Whats ever it would be in your database, to remove an selected item from listview you must have to pick up the selected listitem object not the listitem index value.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.