12.9. Letters

 < Day Day Up > 

If you remember the Word automation example, it is relatively easy to automate the production of a Word document with data from a database. The best way to implement this is with Form Fields, using the same name for the form field (by setting the bookmark property) as you use in the database. To make your application the most flexible, it is better to use the For Each...Next loop to loop through the form fields on the Word document, rather than all of the fields in the table or query that you use. The reason for this is that you can have fields in the database that you do not want in the letter. Rather than having to creating a procedure for each letter, you can use one procedure for all of them.

The easiest way to implement this is to have a form with two fields and a button. The first field asks for a table or query name (you could also put the names of the tables and/or queries in a combo box), and the second field holds the filename and path of the Word document. When you press the button, the application opens the Word document and a recordset with the table or query selected.

Next, fill in each form field, save the document, and move to the next method to start over again. You could use the same form to send marketing letters, collection letters, service reminders, etc. Create a query that gives you the information you want, and create a Word document with form fields for the data you want to pull in. This is easy to program and also meets the client's need to be able to change the Word document without programming.

     < Day Day Up > 


    Integrating Excel and Access
    Integrating Excel and Access
    ISBN: 0596009739
    EAN: 2147483647
    Year: 2005
    Pages: 132

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net