deleting multiple item on listbox 
Author Message
 deleting multiple item on listbox

I am doing a database program which have a listbox. The listbox contains

data from one of the table in the database and it uses an extended
multiple
selection. I am having a problem while deleting these items in the
listbox.
For example, when I delete items 1 & 3 or 2 & 4 on the listbox, it will
delete the wrong item in the database. The following is my coding for
the
deletion.

First, I loop through the listbox to determine selected items, if
detected,
remove it from the listbox, and loop through the table and find the
record
which have the same name and a specific ID.

Private Sub cmdDel1_Click()

 For m = lstT1.ListCount - 1 To 0 Step -1
        If lstT1.Selected(m) Then

           n1t = lstT1.Text
        lstT1.RemoveItem (m)

        Data2.Recordset.MoveFirst

        Do Until Data2.Recordset.EOF
            If Data2.Recordset("songID") = n1t Then
            If Data2.Recordset("index") = storeindex1(m) Then
            Data2.Recordset.Delete
            End If
            End If
        Data2.Recordset.MoveNext
        Loop
        End If
 Next

is there anything wrong with the code? thanks a lot in advance :)



Thu, 12 Sep 2002 03:00:00 GMT  
 deleting multiple item on listbox

Quote:

> I am doing a database program which have a listbox. The listbox contains
> data from one of the table in the database and it uses an extended
> multiple
> selection. I am having a problem while deleting these items in the
> listbox.
> For example, when I delete items 1 & 3 or 2 & 4 on the listbox, it will
> delete the wrong item in the database. The following is my coding for
> the
> deletion.
> First, I loop through the listbox to determine selected items, if
> detected,
> remove it from the listbox, and loop through the table and find the
> record
> which have the same name and a specific ID.
> Private Sub cmdDel1_Click()
>  For m = lstT1.ListCount - 1 To 0 Step -1
>         If lstT1.Selected(m) Then
>            n1t = lstT1.Text

Maybe you want n1t = lstT1.List(m) instead?

Quote:
>         lstT1.RemoveItem (m)
>         Data2.Recordset.MoveFirst
>         Do Until Data2.Recordset.EOF
>             If Data2.Recordset("songID") = n1t Then
>             If Data2.Recordset("index") = storeindex1(m) Then
>             Data2.Recordset.Delete
>             End If
>             End If
>         Data2.Recordset.MoveNext
>         Loop

Why not:

 data2.recordset.findfirst "songid = " & n1t & " and index = " & storeindex1(m)
 if data2.recordset.nomatch = false then data2.recordset.delete

Also, why not use lstT1.ItemData instead of a separate array? Otherwise,
the listbox and the array can fall out of synch as items are added and
deleted.

Quote:
>         End If
>  Next

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!


Thu, 12 Sep 2002 03:00:00 GMT  
 deleting multiple item on listbox

Quote:

> Maybe you want n1t = lstT1.List(m) instead?

thank you for your help :) .. can you tell me what is the List in the listbox
do? because I am a newbie in Visual Basic. :)  is it return all the values in the
selected listbox?

thank you very much.



Fri, 13 Sep 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Question: Deleting Multiple Items in ListBox??

2. ListBox (w/Checkboxes)....Deleting Multiple-Selected Items

3. ListBox (w/Checkboxes)....Deleting Multiple-Selected Items

4. Delete Item in an array which corresponds to Itemsselected in multiselect listbox

5. Help...ListBox Deleting Multi-Selected Items

6. How To:Deleting item from ListBox;vb6

7. Selection Of Multiple Items In Listbox/Combo Box And Inserting Them Into SQL Server

8. Multiple items in ListBox

9. Copy Multiple Items From Listbox to Clipboard

10. Retreiving multiple ListBox Items

11. Listbox with multiple items in it?

12. Multiple items in ListBox

 

 
Powered by phpBB® Forum Software