Tim L
Registered User.
- Local time
- Today, 12:31
- Joined
- Sep 6, 2002
- Messages
- 414
How do you merge to a Word template and save with new filename?
1. Users click a command button.
2. A table is created (done via a make-table query) which contains all of the data from the currently displayed record which is to be linked to a Word Template file (unfortunately, due to some network issues, Word/the template file cannot access the query directly - at least that is the reason I have been told).
3. The word template file is opened via:
4. The user views the template in Word, adjusting anything if necessary and printing off the document.
5. The user saves the document.
Problems:
1) The User still needs to click on the merge field toggle toolbar icon to get the correct data to display (if set to automatically display they need to click it twice, off then on).
2) How can I get the file to save with a predetermined filename? - One of the merge fields is already set up to provide this information and I have placed this field on the first line of the template as white text so that it remains hidden, but if opened using the above method the document is opened as the file and not as a new document based on the template - if opened manually then then Save is selected the filename is picked up (although typical Word it is ignoring everything after the first the underscore that I substituted for the spaces) .
I'm not that good with VBA, I you can't already tell! So a guiding hand on how to go about acheiving the above would be useful.
The key points are:
I have seen some other examples (which looked very complicated) which involve passing the SQL for the mail-merge. I am dubious as to whether this will work due to the network access problem (only some of the queries can be seen by Word when the file is located where it will need to be stored). Also, the SQL for the query will be quite long; although I would only copy it out of the Query builder, it is still likely to cause an issue in the VBA editor, for readability, if for nothing else.
Tim
1. Users click a command button.
2. A table is created (done via a make-table query) which contains all of the data from the currently displayed record which is to be linked to a Word Template file (unfortunately, due to some network issues, Word/the template file cannot access the query directly - at least that is the reason I have been told).
3. The word template file is opened via:
Dim objWord as Object
Set objWord = GetObject("filename","Word.Document")
(this is not my knowledge, I got the idea from searching the forum)Set objWord = GetObject("filename","Word.Document")
4. The user views the template in Word, adjusting anything if necessary and printing off the document.
5. The user saves the document.
Problems:
1) The User still needs to click on the merge field toggle toolbar icon to get the correct data to display (if set to automatically display they need to click it twice, off then on).
2) How can I get the file to save with a predetermined filename? - One of the merge fields is already set up to provide this information and I have placed this field on the first line of the template as white text so that it remains hidden, but if opened using the above method the document is opened as the file and not as a new document based on the template - if opened manually then then Save is selected the filename is picked up (although typical Word it is ignoring everything after the first the underscore that I substituted for the spaces) .
I'm not that good with VBA, I you can't already tell! So a guiding hand on how to go about acheiving the above would be useful.
The key points are:
- The user needs to review the document before printing it.
- The whole process should be as transparent to the user as possible.
- I'm *really* stretching my VBA knowledge here!
I have seen some other examples (which looked very complicated) which involve passing the SQL for the mail-merge. I am dubious as to whether this will work due to the network access problem (only some of the queries can be seen by Word when the file is located where it will need to be stored). Also, the SQL for the query will be quite long; although I would only copy it out of the Query builder, it is still likely to cause an issue in the VBA editor, for readability, if for nothing else.
Tim
Last edited: