I’ve spent whole 3 days to resolve a problem in my program. I still didn’t do that and therefore I decided to ask here for help.

-My program have TreeView and ListView control. After selecting an item from TreeView, program fills ListView up from database.
-ListView has right-click context menu with options for adding a copy of existing item and deleting an item from ListView and from database itself.

Everything works fine except two things:

1. When I’m deleting a listview item, it is wiped out from the database but it is still shown as a ListView item. If I change selected item from TreeView and come back to the previous one, the item from ListView is deleted. Also, if I’m working in debugging mode, everything’s working fine.

I’ve tried many things to resolve this issue without success.

2. The second problem is related with adding a copy of existing item to the database. It works fine for the first attempt of copying But, if I click new formed item with mouse, I’m getting an error: 3021: Either BOF or EOF is true.. etc etc… I’m not sure why I get this message if I only click on new item which is exactly a copy of an existing item?

Any help would be helpful
rgds


Here's a code which updates ListView from database:

VB Code:
  1. Public Sub UpdateMainLV()
  2. 'subroutine updates ListView control from database
  3.  
  4.     Dim con33 As ADODB.Connection
  5.     Dim rs33  As ADODB.Recordset
  6.  
  7.     Set con33 = New ADODB.Connection
  8.     con33.CursorLocation = adUseClient
  9.     con33.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb"
  10.     Set rs33 = New ADODB.Recordset
  11.  
  12.     frmViewer.ListView1.ListItems.Clear ''==============
  13.    
  14.     Dim SQL33 As String
  15.     SQL33 = "SELECT * FROM base_rec WHERE sub_cat = " & "'" & frmViewer.TreeView1.SelectedItem.Text & "'" & " AND lv_category= " & "'" & frmViewer.TreeView1.SelectedItem.Parent.Text & "' ORDER BY sub_cat DESC;"
  16.     rs33.Open SQL33, con33, 3, 4
  17.     rs33.MoveFirst
  18.    
  19.     Dim i As Integer
  20.  
  21.     For i = 0 To rs33.RecordCount - 1
  22.         Set lvwItem = frmViewer.ListView1.ListItems.Add(1, , rs33.Fields!lv_category)
  23.         lvwItem.SubItems(1) = rs33.Fields!sub_cat
  24.         lvwItem.SubItems(2) = rs33.Fields!lvp_name
  25.         lvwItem.SubItems(3) = rs33.Fields!comment
  26.         lvwItem.SubItems(4) = rs33.Fields!date
  27.         rs33.MoveNext
  28.     Next i
  29.  
  30.     rs33.Resync
  31.     rs33.Close
  32.     con33.Close
  33.     Set rs33 = Nothing
  34.     Set con33 = Nothing
  35.    
  36.     frmViewer.ListView1.Refresh

And here's a code which calls this routine :


VB Code:
  1. Private Sub mnulvDelete_click() '<============== BRISI LV ITEM
  2.  
  3.     Dim con         As ADODB.Connection
  4.     Dim rs7         As ADODB.Recordset
  5.  
  6.  
  7.     Dim SQL7 As String
  8.     SQL7 = "SELECT * FROM base_rec WHERE lvp_name='" & CStr(lblSel.Caption) & "';"
  9.  
  10.     Set con = New ADODB.Connection
  11.     con.CursorLocation = adUseClient
  12.     con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb"
  13.     Set rs7 = New ADODB.Recordset
  14.     rs7.Open SQL7, con, 3 , 4
  15.            
  16.     rs7.Delete
  17.    
  18.     rs7.Update
  19.     rs7.Resync
  20.     rs7.Close
  21.  
  22.  
  23.     Dim indx As Integer
  24.     Dim lvrows As Integer
  25.  
  26.     lvrows = ListView1.ListItems.Count
  27.     For indx = 1 To lvrows
  28.         If indx > lvrows Then Exit For
  29.  
  30.         If Trim(ListView1.ListItems(indx).SubItems(2)) = Trim(lblKliknutoNa.Caption) Then
  31.             ListView1.ListItems.Remove (indx)
  32.             indx = indx - 1
  33.             lvrows = lvrows- 1
  34.         End If
  35.    Next
  36.  
  37. Call frmKV.UpdateMainLV
  38.  
  39. End Sub