You need to check the result of SearchHierarchy and returns it if is not null:
Private Function SearchHierarchy(Orgs As ObservableCollection(Of Organization), ID As Integer) As String
For Each Org As Organization In Orgs
Console.WriteLine("SearchHierarchy Enter :" + Org.Name)
If Org.OrganizationID = ID Then
Return Org.Name
Else
If Org.Subsidiaries IsNot Nothing Then
Dim result As String = SearchHierarchy(Org.Subsidiaries, ID)
If Not String.IsNullOrWhiteSpace(result) Then
Return result
End If
End If
End If
Console.WriteLine("SearchHierarchy Leave:" + Org.Name)
Next
Return String.Empty
End Function
Suggestion
I prefer to write a recursive function on the simple class type, not a collection. For example, in your scenario, I would write SearchHierarchy in this way:
Private Function SearchHierarchy(Org As Organization, ID As Integer) As String
If Org.OrganizationID = ID Then
Return Org.Name
ElseIf Org.Subsidiaries IsNot Nothing Then
For Each subOrg As Organization In Org.Subsidiaries
Dim result As String = SearchHierarchy(subOrg, ID)
If Not String.IsNullOrWhiteSpace(result) Then
Return result
End If
Next
End If
Return String.Empty
End Function
Please note this is a suggestion and I share it just in case you like it too.