how can i save a data in listview1? i have a problem to my code heres my code

Dim objNewListItem As ListItem
Set rs = New ADODB.Recordset
rs.Open "Select * from Supplier", cn, adOpenKeyset, adLockPessimistic
rs.MoveFirst

Do While Not rs.EOF
    Set objNewListItem = lvwCustomer.ListItems.Add(, , rs.Fields("scode"))
    objNewListItem.SubItems(mlng_Supp_Name) = rs.Fields("sname") & ""
    objNewListItem.SubItems(mlng_Supp_Address) = rs.Fields("saddress") & ""
    objNewListItem.SubItems(mlngSuppContactno) = rs.Fields("scontactno")
    rs.MoveNext
Loop

everytime i click my command button, the list item in a listview1 is having a duplication. .
help me thanks. .

Before reloading a list view, combobox or other controls like this use .Clear

lvwCustomer.clear

empty old values and reload again

i have an error

Operation is not allowed when the object is closed?

something in the bigger picture is amiss.

clear the list view control first, then open and run your database connection and listview filler sub

Doe them in two separate functions or subs to keep things clear, simple and debuggable.

can u post the code sir? so i can know. . thanks

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.