ClaraBarton
Registered User.
- Local time
- Today, 13:36
- Joined
- Oct 14, 2019
- Messages
- 764
@MajP I'm sorry but I can only work on this a little at a time so it's dragging out...
Item details (add, edit, remove, etc) are on a subform and the treeview is on the mainform. I don't delete items as such but only clear fields so that the DocNo stays and is used as items new are added or tacked on the end if no blank records. So I needed to rework the delete. I am deleting the node before I delete the item so that I can grab the node key. All seems very logical to me but so far not so much -- the line tvw.Nodes.Remove (ItemNode) returns element not found. The item node debugs the node text so I don't get what can't be found.
Item details (add, edit, remove, etc) are on a subform and the treeview is on the mainform. I don't delete items as such but only clear fields so that the DocNo stays and is used as items new are added or tacked on the end if no blank records. So I needed to rework the delete. I am deleting the node before I delete the item so that I can grab the node key. All seems very logical to me but so far not so much -- the line tvw.Nodes.Remove (ItemNode) returns element not found. The item node debugs the node text so I don't get what can't be found.
Code:
Public Sub DeleteItem()
Dim strSql As String
Dim lDocNo As Long
Dim Position As Long
Position = Me.CurrentRecord
strSql = "UPDATE tblItems SET" & _
" InUse = 0," & _
" Item = Null," & _
" Purchased = Null," & _
" AmountPaid = Null," & _
" Notes = Null," & _
" Modified = Date()" & _
" WHERE ItemID = " & Me.ItemID
DeleteItemNode
SQLExecute (strSql)
With Me.Recordset
.Requery
If Position > 1 Then
.Move Position - 1
Else
.Move Position + 1
End If
End With
Me.Item.SetFocus
End Sub
Code:
Public Sub DeleteItemNode()
Dim tvw As TreeviewForm
Dim ParentNode As Node
Dim ItemNode As Node
Set tvw = GetItemTreeView
Set ItemNode = tvw.Nodes("IT" & Me.ItemID) 'element not found
Set ParentNode = tvw.Nodes("LO" & Me.fLocID)
tvw.Nodes.Remove (ItemNode)
ParentNode.Selected = True
tvw.TreeView.DropHighlight = ParentNode
End Sub
Last edited: