Skip to content

Merging data from linked tables

How to merge data from linked tables

Q:  Lisa Hartley writes:  I’m planning to use the code in code2.zip to merge data from Access into word documents.  Could you please give a couple lines of sample code which would tell me how to get data from a related table. In other words I have:

Table A

with a one to many relationship to Table B

Form A is based on Table A and includes a reference to the primary key of Table B

I now want to grab data not only from Form A (as you do in your sample code) but also from other fields in Table B

A:  The simplest way is to make a query containing the linked tables, and select all the fields you want to use from both tables.  Then use that query as the data source for the merge.  If you need something more complex, like listing all the records from the “many” table in a section on the Word document, see Access Archon #44.  Also, you might want to look at Code Sample #24 (Four Ways to Merge to Word) for other approaches.  (Generally, the doc properties method is the best.)

About this author