Automating Word from Access

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I've used the code at described in 'How to send the current record to Word 2000 with automation' (http://support.microsoft.com/Default.aspx?kbid=210271}
to do what it says on the can. It works by opening a Word document containing bookmarks, setting the value of Word bookmarks to those of fields in the Access form, saving the results as a new document and closing the old one unsaved, thus retaining it for future use.


I far prefer this to the alternative technique of opening a new document from a template that uses an Access query as the datasource since it's a lot faster. However, there's one drawback.

If you merge a Word document, Word takes out any blank lines in the address and adjusts the spacing accordingly. This doesn't, though, work with bookmarks, so if I've got fields in my query (and bookmarks ready to receive their contents) AddressLine1, AddressLine2 and City, and the particular record doesn't have an entry for AddressLine2, the resulting Word document has an unsightly gap between the first (and only, in this case) line of the address and the city.

Is there a way to address this problem at the Access end, possibly by having something in the code to delete the bookmark AddressLine2 and the carriage return if MyAccessQuery.AddressLine2 is null? How would I do this?

Steve
.



Relevant Pages

  • Re: Automating Word from Access
    ... I do this by using a single bookmark for the address, ... >containing bookmarks, setting the value of Word bookmarks to those of ... >If you merge a Word document, Word takes out any blank lines in the ... >ready to receive their contents) AddressLine1, AddressLine2 and City, ...
    (microsoft.public.access.gettingstarted)
  • Re: Automating Word from Access
    ... I do this by using a single bookmark for the address, ... containing bookmarks, setting the value of Word bookmarks to those of ... If you merge a Word document, Word takes out any blank lines in the ... ready to receive their contents) AddressLine1, AddressLine2 and City, ...
    (microsoft.public.access.gettingstarted)
  • Using Excel VBA to control Word (open document)
    ... I have excel VBA code that does a bunch of stuff in Excel, ... determined by the XL VBA code, then save the Word document under a new name. ... bookmarks resets the bookmark count which means that I'm not deleting all ...
    (microsoft.public.excel.programming)
  • Microsoft Word Merge with Bookmarks and Multiple Pages
    ... query to a Word Document that includes ... bunch of Bookmarks that I want to populate from my query ... sTextToUse As String) ...
    (microsoft.public.access.modulesdaovba)
  • RE: Can I extract a XSLT from a Word DOcument?
    ... > We use Bookmarks for the Data and we use Special Bookmarks for Paragraphs ... This will also involve a re-design of the Doc Creation App. ... > how can I for example extract an XSLT from a Word Document? ... to create the XML data in our Doc Creation App and use a Style ...
    (microsoft.public.word.vba.general)