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.

Recommended Answers

All 4 Replies

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

In database it was numeric. so what problem?

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.

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.