TrkItem.RelativeItems (read-only property)

property RelativeItems
Syntax: TrkItems = object.RelativeItems
Description:
Returns the collection of TrkItem objects, which are relative to this TrkItem. To get the relative items, call the ReadDB method on the RelativeItems collection. If there are no relative items in the database, then the collection will be empty.

Example 1:

How to get specific Relative Items.

Dim oTADBRoot As Object
Dim oTrkItem As Object
Dim oRelativeItem As Object

Set oTADBRoot = CreateObject("TADB.TADBRoot")

If oTADBRoot Is Nothing Then
   MsgBox "Root Object is not created"
End If

oTADBRoot.Load "TRK7", ""

oTADBRoot.TrkItems.ReadDB ("Item9")
If oTADBRoot.TrkItems.Count=1 Then
   'Item is loaded from database.
   Set oTrkItem = oTADBRoot.TrkItems.Item("Item9")
   'To load specific relative item pass that item id.
   oTrkItem.RelativeItems.ReadDB ("Item5")
   For Each oRelativeItem In oTrkItem.RelativeItems
       MsgBox oRelativeItem.ID
   Next
Else
    'Item does not exist in database....
End If

Example 2:

How to get all relative Items.

Dim oTADBRoot As Object
Dim oTrkItem As Object
Dim oRelativeItem As Object

Set oTADBRoot = CreateObject("TADB.TADBRoot")

If oTADBRoot Is Nothing Then
   MsgBox "Root Object is not created"
End If

oTADBRoot.Load "TRK7", ""

oTADBRoot.TrkItems.ReadDB ("Item9")
If oTADBRoot.TrkItems.Count=1 Then
   'Item is loaded from database.
   Set oTrkItem = oTADBRoot.TrkItems.Item("Item9")
   'To load all relative item...
   oTrkItem.RelativeItems.ReadDB
   For Each oRelativeItem In oTrkItem.RelativeItems
       MsgBox oRelativeItem.ID
   Next
Else
    'Item does not exist in database....
End If

Example 3:

How to add Relative Items.
The example adds Item2 and Item3 as relatives of Item9 with the assumption that Item2 and Item3 are present in the database.

Dim oTADBRoot As Object
Dim oTrkItem As Object
Dim oRelativeItem As Object 'RelativeItem object

Set oTADBRoot = CreateObject("TADB.TADBRoot")

If oTADBRoot Is Nothing Then
   MsgBox "Root Object is not created"
End If

oTADBRoot.Load "TRK7", ""

oTADBRoot.TrkItems.ReadDB ("Item9")
If oTADBRoot.TrkItems.Count=1 Then
   'Item is loaded from database.
   Set oTrkItem = oTADBRoot.TrkItems.Item("Item9")
   oTrkItem.RelativeItems.Add ("Item 2")
   oTrkItem.RelativeItems.Add ("Item 3")
   oTrkItem.Save
Else
    'Item does not exist in database....
End If

Example 4:

How to add a new relative Item.
Adds Item50 as a relative of Item9 regardless of its existence in the database

Dim oTADBRoot As Object
Dim oTrkItem As Object
Dim oRelativeItem As Object 'RelativeItem object

Set oTADBRoot = CreateObject("TADB.TADBRoot")

If oTADBRoot Is Nothing Then
   MsgBox "Root Object is not created"
End If

oTADBRoot.Load "TRK7", ""

oTADBRoot.TrkItems.ReadDB ("Item9")
If oTADBRoot.TrkItems.Count=1 Then
   'Item is loaded from database.
   Set oTrkItem = oTADBRoot.TrkItems.Item("Item9")
   Set oRelativeItem = oTrkItem.RelativeItems.Add ("Item50")
   If Not oRelativeItem Is Nothing then
        ' Item50 is added successfully....
        oRelativeItem.ReferenceID = "XYZRefID"
        oRelativeItem.ItemTypeID = "VEHICLE ORDER"
        oRelativeItem.Save
        oTrkItem.Save
   Else
        ' Item50 is not added successfully....
   End If
Else
    'Item does not exist in database....
End If

Example 5:

How to Remove Relative item.
Let's assume that "Item9" has relative items "Item2", "Item3" and "Item50" -- the example removes "Item2" and "Item50" from relative item collection.

Dim oTADBRoot As Object
Dim oTrkItem As Object
Dim oRelativeItem As Object 'RelativeItem object

Set oTADBRoot = CreateObject("TADB.TADBRoot")

If oTADBRoot Is Nothing Then
   MsgBox "Root Object is not created"
End If

oTADBRoot.Load "TRK7", ""

oTADBRoot.TrkItems.ReadDB ("Item9")
If oTADBRoot.TrkItems.Count=1 Then
   Set oTrkItem = oTADBRoot.TrkItems.Item("Item9")
   'Load all relative items
   oTrkItem.RelativeItems.ReadDB
   'Item is loaded from database.
   oTrkItem.RelativeItems.Remove "Item2"
   oTrkItem.RelativeItems.Remove "Item50"
Else
    'Item does not exist in database....
End If