I have a main table and multiple other tables that I want to link to each row of the main table.
The main table "Data" consists of columns (Name, x, y) where "Name" is the primary key and all values are unique.
Each of the other tables have columns (Name2, z) where the value of "Name2" is the same in each row and also corresponds to the table name.
I want to make each table a subdatasheet of "Data" where each row in "Data" shows the values in the table corresponding to its name. (i.e. where Name = Name2)
Below is what I have so far, but the code doesn't work because linkchildfields and linkmasterfields need to be run from a subform.(?) I'm new to Access so can anyone please help me set these subforms up or show me how this can be done?
The error I am getting is 'Property Not Found' once the code reached the linkchildfields line.
Thanks.
The main table "Data" consists of columns (Name, x, y) where "Name" is the primary key and all values are unique.
Each of the other tables have columns (Name2, z) where the value of "Name2" is the same in each row and also corresponds to the table name.
I want to make each table a subdatasheet of "Data" where each row in "Data" shows the values in the table corresponding to its name. (i.e. where Name = Name2)
Below is what I have so far, but the code doesn't work because linkchildfields and linkmasterfields need to be run from a subform.(?) I'm new to Access so can anyone please help me set these subforms up or show me how this can be done?
The error I am getting is 'Property Not Found' once the code reached the linkchildfields line.
Thanks.
Sub STS()
Dim i As TableDef
Dim db As Database
Dim tbl As TableDef
Set db = CurrentDb()
Set tbl = db.TableDefs("Data")
For Each i In db.TableDefs
If Left$(i.Name, 4) <> "MSys" Or i.Name <> "Data" Then
tbl.Properties("SubdatasheetName") = i.Name
tbl.Properties("LinkChildFields") = "Name2"
tbl.Properties("LinkMasterFields") = "Name"
End If
Next
End Sub