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

        Set con = Nothing

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

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.

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 8 Months Ago by Shark_1

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 article has been dead for over six months. Start a new discussion instead.