Database-based word document

1

I will take an example, it'll be easier:

So I have a database about classrooms. There is student db which contains all the students like so:

id     name    surname     slug      class
0      John    Doe         JOHN_DOE  6_A
1      John    Doe         JOHN_DOE2 6_B
...    ...     ...         ...       ...

(this is an hypotesis)

Now I would like to have for instance ms word document that I can print everywhere with for example, a page per class containing a table of all students, automatically updating with new or updated students.

Is there a way to use Word as a template engine (?), powered by Microsoft Access without (or little as possible) macros on MS Word 2007?

Vinz243

Posted 2014-09-04T16:55:44.130

Reputation: 83

1This will likely end badly. Word is not a database application. Would something like Microsoft Access (which is a database) that generates reports work for you? This would be very doable in Access. – Darth Android – 2014-09-04T17:09:23.807

AS @DarthAndroid suggests, use the DB server to run a report (most support this in some form). Or how about using Excel as the front end instead (it's much better at tying into DBs)? http://blogs.office.com/2012/08/14/plug-into-your-data-connecting-excel-to-an-access-database/

– Ƭᴇcʜιᴇ007 – 2014-09-04T17:24:48.537

Thanks, I don't want to use Word as a DB, but rather as a template engine (I'm coding a backend, that's why I'm thinking of this) – Vinz243 – 2014-09-04T18:37:10.647

You can do a "one-many" mailmerge in Word using field codes alone as long as you can get the data in the correct sequence and the final record is easy to identify. You really have to "think in reverse" to get the field coding right. The other merge-based method requires that your merge data source has one record per class, and uses a DATABASE field to retrieve the students for each class. You have little control over the layout of the table, especially if it spills over onto two pages. If all you have is a student table, you will still need VBA to issue the SQL to give you the class table. – None – 2014-09-04T19:59:05.837

Thank you, any example? – Vinz243 – 2014-09-05T10:27:23.287

For example, use a query/view such as "SELECT Distinct class FROM student ORDER by class" to create the mailmerge data source, and a DTAABASE field such as { DATABASE (you'll have to provide a database name or a .odc file name depending on the data osurce type) \s "SELECT c.* FROM class c WHERE c.class = '{ MERGEFIELD class }' } , where all the { } are the special field code brace pairs that you can insert using ctrl-F9 on Windows Word. – None – 2014-09-07T15:15:17.303

No answers