I have a job
table
Id
ParentID
jobName
jobStatus
The root ParentID is 0.
Is it possible in Access to create a query to
I had a related problem working with a treeview structure, when a user wants to delete a node, he wants to delete all then nodes under that tree. Childs, childs of childs etc etc.
A job for recursion....
So to delete the data in your table to match the treeview node deletes, use a recursive function that will delete the node, and recurse down and delete all the nodes that are children, grandchildren ect.
example of the function:
Public Sub RemoveChildKeys(MyKey)
' deletes passed key and removes all children and grandchildren ect etc of passed key recursively
Dim TheDB As DAO.Database
Dim TheTable As DAO.Recordset
Dim MySql As String
Set TheDB = CurrentDb
MySql = "Select * from TblIndex WHERE [Parent]=" & MyKey & ";"
Set TheTable = TheDB.OpenRecordset(MySql)
While Not TheTable.EOF
RemoveChildKeys (TheTable!Key) ' <---- Calls itself
TheTable.MoveNext
Wend
DoCmd.RunSQL "Delete * FROM TblIndex WHERE [Key]=" & MyKey ' delete in table
End Sub