Full Version: I Can't Believe How Difficult This Is. Access To Word ...
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
rowman
I can't believe how much trouble I am having creating a button on a form that when click will open a word doc and write data fields from the form to the word doc. I have read over 40 threads of this and tried over 15 different methods and have come up with squat. I would appreciate anyone who can help me get through this. Here is the goal:

I have a form with an organization_name field (and other fields but lets keep it simple) that is open to a record. I need to print a long waiver/legal type document that has several references within the time to the organization_name field. I am familiar with doing a mail merge but my goal is to have a button that will open the waiver.doc and populate the fields sot that I can print it (printing doesn't need to be automated). Going through the process of mail merge isn't desirable as I have to do this 300+ times a month.

Here's what I have tried and failed with:

I have tried doing this through access reports. It doesn't work bc the waiver is several pages long.

I have tried the method of creating a button that runs a vb code to open the doc and write the field to bookmarks. It always fails at Dim myApp As Word.Application with error code: User defined type not defined. I have the Microsoft Office Library 14.0 referenced in references. When i try to reference DAO as suggested to me it comes up with some kind of duplicate name error.

Any ideas that I can try? It seems like this should be an easy thing but I feel like I'm asking the moon and stars.

zocker
QUOTE
I have tried doing this through access reports. It doesn't work bc the waiver is several pages long.


The objection to using an Access report should be that its text formatting is not as rich as that of Word. You can have an unlimited number of pages on a Report. (look at page break control). If at all possibe stay with Access reports for your doc. it will simplify everything and should you distribute the program you will avoid several problems. There are rich text controls that you can add in and I believe Access 2007+ has rich text.

HTH

Zocker
Kamulegeya
QUOTE (rowman @ May 17 2012, 08:32 AM) *
I can't believe how much trouble I am having creating a button on a form that when click will open a word doc and write data fields from the form to the word doc. I have read over 40 threads of this and tried over 15 different methods and have come up with squat. I would appreciate anyone who can help me get through this. Here is the goal:

I have a form with an organization_name field (and other fields but lets keep it simple) that is open to a record. I need to print a long waiver/legal type document that has several references within the time to the organization_name field. I am familiar with doing a mail merge but my goal is to have a button that will open the waiver.doc and populate the fields sot that I can print it (printing doesn't need to be automated). Going through the process of mail merge isn't desirable as I have to do this 300+ times a month.

Here's what I have tried and failed with:

I have tried doing this through access reports. It doesn't work bc the waiver is several pages long.

I have tried the method of creating a button that runs a vb code to open the doc and write the field to bookmarks. It always fails at Dim myApp As Word.Application with error code: User defined type not defined. I have the Microsoft Office Library 14.0 referenced in references. When i try to reference DAO as suggested to me it comes up with some kind of duplicate name error.

Any ideas that I can try? It seems like this should be an easy thing but I feel like I'm asking the moon and stars.



Hello

I do word automation using bookmarks

Create a template document and insert bookmarks in places you want to populate data from access

User a recordset to populate the bookmarks

I can share the code i use if you want

Ronald
Galaxiom
QUOTE (rowman @ May 17 2012, 04:32 PM) *
It always fails at Dim myApp As Word.Application with error code: User defined type not defined. I have the Microsoft Office Library 14.0 referenced in references.

Microsoft Word 14.0 Object Library

QUOTE
It seems like this should be an easy thing but I feel like I'm asking the moon and stars.


Throw in some planets and a few galaxies too.
The Microsoft Word Document Object Model is is one of the most elaborate you are likely to encounter.
rowman
ZOCKER- Thank you for the feedback. Believe me I would love to use reports but I have been unsuccessful at making it work. Maybe you can help me troubleshoot the issues. The first issue is that when I create a text box and paste the contents of the waiver copied from the word doc it get the error "The text is too long to be edited." If I just paste the content without creating a textbox it comes up as an image and I am not able to add the fields inline with the text (and thus have the text wrap as the lengths of the fields are different).

Any suggestions?
rowman
KAmul- This is exactly what I am trying to do and getting the errors listed above. If you would like to share teh code you use that would be helpful but I have tries at least 10 different code samples to no avail at this point. Thanks.
CyberCow
WORD LINKS :
Sending the Current Record to Word 97 with Automation (should still work with later versions)
Word Automation, Part I
Word Automation, Part II
Word-VBA Code Samples 

hope this helps
AlbertKallal
I have a nice working sample that does a merge of the current record to word.

The sample I have can be found here:
http://www.kallal.ca/msaccess/msaccess.html

What is nice/interesting about my sample is that is specially designed to enable ANY form with ONE LINE of code....

Thus, each time you build a new form, you can word merge enable it with great ease.

Make sure you read the instructions from above, and you should eventually get to the following page
http://www.kallal.ca/wordmerge/page2.html

Note that the merge can also use a query, and thus you don't have to merge just "one" record..

After the merge occurs, you get a plain document WITHOUT any merge fields, and this allows the end user to save, edit, or even email the document (since the merge fields are gone after the merge occurs).

Give the above a try. It is a hunk of code more then 10 years old - works for all versions of office I used it with, and as noted: ONE line of code is required to be placed in your form.

Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
kallal@msn.com
JonSmith
Hi,

I'd like to throw my solution into the ring, I have gone down the route of using a document template (dot or dotx) and bookmarks, this is due to me using confidential info and not wanting that saved anywhere.
It is called from a function and will automatically loop through all the bookmarks and match them to fields in your dataset, you can set it so you can use the same multiple times on each from and you can also have continuous records on the same form (same field, different record). It also supports custom additional bookmarks and values that can be specified in code outside of the SQL query.

Attached is a working example. The naming logic that makes it work and general info is documented in the code.

Jon Smith
zocker
re Text is too long....

Use more than one text box, perhaps one for each paragraph, If you base your text boxes on a table, say tblParagraphs, you or users can then edit your text on an Access form which you can create. I have to add that I have used this technique for very long legal rental contracts, I experimented long with exporting to Word, using Bookmarks and straightforward dumping to Word. Since on the contracts I was writing, several items appeared many times, company name eg. I found that each bookmark has to have a distinct name and what appeared to be quite simple turned into a confusing nightmare with over 30 bookmarks. I am quite certain you can do all this in Access reports.
The only other reason I found apart from formatting issues with Reports was that if you email a Report which has images, the images will be removed and that includes lines and other graphic stuff.........why Msoft havent dealt with instead of all the other improvements..... that I cannot know

Best of luck, post again for more help!
JonSmith
QUOTE (zocker @ May 17 2012, 07:51 PM) *
re Text is too long....

Use more than one text box, perhaps one for each paragraph, If you base your text boxes on a table, say tblParagraphs, you or users can then edit your text on an Access form which you can create. I have to add that I have used this technique for very long legal rental contracts, I experimented long with exporting to Word, using Bookmarks and straightforward dumping to Word. Since on the contracts I was writing, several items appeared many times, company name eg. I found that each bookmark has to have a distinct name and what appeared to be quite simple turned into a confusing nightmare with over 30 bookmarks. I am quite certain you can do all this in Access reports.
The only other reason I found apart from formatting issues with Reports was that if you email a Report which has images, the images will be removed and that includes lines and other graphic stuff.........why Msoft havent dealt with instead of all the other improvements..... that I cannot know

Best of luck, post again for more help!


I have struggled massively with trying to sort out reports built in with Access when they are supposed to conform to a Word style letter or a table or something and actually find working with Word and Bookmarks much easier (I would like to point out that I hate Word and avoid at all costs, I would rather do anything I can do in Word in Publisher). Its why I came up with the solution I posted earlier because I am effectively putting the flexibility of multiple bound controls (Word Bookmarks with a specific naming convention, no different than binding a control source) into the Word wrapper.

I've got to say, Access is awesome but I find reports are the most lacking (They are still very good useful tools).
CyberCow
@JonSmith - not to be contrary, but Access reports are quite robust once you get the hang of using them. Mastering that use takes a good bit of trial & error and much experience; but can be very precise if time is taken to learrn how they work and can work for you. I don't believe there is another tool out there that can approach the behavior of Access report design. </imho>
JonSmith
Fair enough, allow me to clarify. I find the lack of ability to customize, save and edit by the end user lacking, particularly in a complied database. The rich text options available in Word in addition to being able to present my end user with a standalone document they can edit and email, save etc makes the juice worth the squeeze in terms of Word Automation. Duplexing options are a pain as well as they seem to Work inconsistently (when setting duplex or simplex via code).

As I said, I hate Word, tables in particular are an absolute nightmare (When I change the size of one column it doesn't mean I want to change the size of all the columns around it to and mess up all established formatting) but I need to use for the purposes outlined above.

I am an old 03 bod so perhaps they have added things in I am not aware of in newer builds but these are the issues I have been contending with, if you can think of a better way to do what my example does (The letter then end user can amend in particular) then I would be thrilled to see it.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.