One approach is to create a record for each value/source table pair in each LK table then use each LK table as source for a CROSSTAB query to get the matrix output.
Another is to add fields to LK tables for each source table.
Instead of deleting and recreating tables, an option is to delete records, which is what I use. I would probably have one LK table with a Category field.
Consider simple code example for first approach with a single LK table (assumes no memo type fields):
Code:
Public Sub GetData()
Dim db As DAO.Database, rs As DAO.Recordset
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("SELECT * FROM Data_Dictionary WHERE Field_Name <> 'Auto_ID'")
CurrentDb.Execute "DELETE * FROM LK"
Do While Not rs.EOF
db.Execute "INSERT INTO LK(Data,Category,Source) SELECT DISTINCT " & rs!Field_Name & ",'" & rs!Field_Name & "','" & rs!Table_Name & "' FROM " & rs!Table_Name
rs.MoveNext
Loop
End Sub
And then a CROSSTAB for BLS_ACCIDENT_TYPE
TRANSFORM Nz(Count("*"),0) AS X
SELECT LK.Data
FROM LK
WHERE (((LK.Category)="BLS_ACCIDENT_TYPE"))
GROUP BY LK.Data
PIVOT LK.Source IN ("tbl_MMAC","tbl_NNSY","tbl_PHNSY","tbl_PNSY","tbl _POIRS");
Now for the other approach code:
Code:
Public Sub GetData_M()Dim db As DAO.Database, rs As DAO.Recordset
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("SELECT * FROM Data_Dictionary WHERE Field_Name <> 'Auto_ID'")
CurrentDb.Execute "DELETE FROM LK_M"
Do While Not rs.EOF
db.Execute "INSERT INTO LK_M(Data,Category," & rs!Table_Name & ") SELECT DISTINCT " & rs!Field_Name & ",'" & rs!Field_Name & "',1 FROM " & rs!Table_Name
rs.MoveNext
Loop
End Sub