Chris said:
This is an Hierarchical table as it has an involuted relationship on itself.
I am not interested in joining two tables but tree walking within the same
table ie. a foreign key on a table is the primary key on the same table.
Therefore one row within that table as a refernce to another row in that table
I'm not sure SHAPE is what you are looking for because it is not
'recursive'. For example using your data in Access
Sub test1()
Dim con As Object
Set con = CreateObject("ADODB.Connection")
With con
.ConnectionString = _
"Provider=MSDataShape;Data " & _
CurrentProject.Connection.ConnectionString
.Open
.Execute _
"CREATE TABLE [Connection] " & _
"(Lower_object_id CHAR(1) NOT NULL PRIMARY KEY, " & _
"Higher_object_id CHAR(1) " & _
" REFERENCES [Connection] (Lower_object_id) " & _
" ON DELETE SET NULL ON UPDATE CASCADE)"
..Execute _
"INSERT INTO [Connection] (Lower_object_id) VALUES ('1')"
..Execute _
"INSERT INTO [Connection] (Lower_object_id) VALUES ('2')"
..Execute _
"INSERT INTO [Connection] (Lower_object_id) VALUES ('3')"
..Execute _
"INSERT INTO [Connection] (Lower_object_id) VALUES ('4')"
..Execute _
"INSERT INTO [Connection] (Lower_object_id) VALUES ('a')"
..Execute _
"INSERT INTO [Connection] (Lower_object_id) VALUES ('b')"
..Execute _
"INSERT INTO [Connection] (Lower_object_id) VALUES ('c')"
..Execute _
"UPDATE [Connection] SET Higher_object_id = '2' WHERE Lower_object_id =
'1'"
..Execute _
"UPDATE [Connection] SET Higher_object_id = '3' WHERE Lower_object_id =
'2'"
..Execute _
"UPDATE [Connection] SET Higher_object_id = '4' WHERE Lower_object_id =
'3'"
..Execute _
"UPDATE [Connection] SET Higher_object_id = 'b' WHERE Lower_object_id =
'a'"
..Execute _
"UPDATE [Connection] SET Higher_object_id = 'c' WHERE Lower_object_id =
'b'"
Dim rs1 As Object
Set rs1 = .Execute( _
"SHAPE {SELECT Lower_object_id, Higher_object_id FROM [Connection]} " &
_
"APPEND ({SELECT Lower_object_id, Higher_object_id FROM [Connection]}"
& _
" AS chapConnection1 RELATE Higher_object_id TO Lower_object_id)")
MsgBox rs1.GetString
rs1.MoveFirst
Dim rs2 As Object
Set rs2 = rs1.Fields("chapConnection1").Value
MsgBox rs2.GetString
End With
End Sub
returns the first level. To get the next level you'd have to relate it
again 'manually' e.g. by opening another hierarchical recordset through
reshaping and so on for each level.
The closest I've seen is for SQL Server:
HOW TO: Show Expanding Hierarchies by Using SQL Server
http://support.microsoft.com/default.aspx?scid=kb;en-us;248915
So if you have to 'fake' it in SQL Server, then you are going to have
to 'fake' it in Access
