Oops.. couple of last minute small corrections:
--------------------------
Public Function GetParent ( ChildField As String ) As String
'
Dim LastParent As String: LastParent = Child
Dim ThisParent As String: ThisParent = Child
Do Until ThisParent = ""
ThisParent = DLookup ( MyTable, ThisParent, ParentField )
If ThisParent <> "" Then LastParent = ThisParent
Loop
GetParent = LastParent
'
End Function
--------------------------
Main Topics
Browse All Topics





by: wsh2Posted on 2007-06-22 at 09:38:06ID: 19342766
This is to get you started. I am not at my computer right now, so it is Air Coded which means you may have to fix errors: You didn't specify field types so I played it safe and made them Strings. ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
--------------------------
Public Function GetParent ( ChildField As String ) As String
'
Dim LastParent: LastParent = Child
Dim ThisParent: ThisParent = Child
Do Until ThisParent = 0
ThisParent = DLookup ( MyTable, ThisParent, ParentField )
If ThisParent <> "" Then LastParent = ThisParent
Loop
GetParent = LastParent
'
End Function
--------------------------
Usage:
SELECT ChildField, GetParent(ChildField)
FROM MyTable
End Function