Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need assistance with controlling MSWord with Access 2

Status
Not open for further replies.

StillLearning

Programmer
Jan 12, 2000
11
US
I assistance with developing code to open a Word file from Access. The Word file will be used to as a report for data from Access. I have been trying to understand the concept of automation without success. Can someone point me in the right direction. Your input is greatly appreciated.
 
Yes, I am doing these steps as I write this<br>
1. Create a query in Access that has ALL of the data to go in your Word doc<br>
2. Open Word and the Doc to receive the data<br>
3. In Word click &quot;tools&quot; menu then &quot;Mail Merge&quot;<br>
4. Click &quot;Create&quot; button, &quot;Form Letter&quot;, &quot;Active window&quot;<br>
5. Click &quot;Get Data&quot; button below Create button<br>
6. Click &quot;Open Data source&quot;<br>
In &quot;Files of type&quot; at the bottom find &quot;MS Access Databases (.MDB)&quot;<br>
7. In the &quot;Look In&quot; dropdown box (at the top) find your drive<br>
Go find your .MDB where ever it is it can be on the server or anywhere.<br>
8. You will see a dialog box click on the &quot;Queries&quot; tab and find your query<br>
9. Click OK (Now this could take a while)<br>
Which if you have a lot of data I strongly suggest you create a report in Access that looks just like your word document (it can be done)<br>
<br>
I'll get back to you when you have this done<br>

 
Doug,<br>
<br>
What about using WORD as an OLE server. Microsoft promote this method in VB tutorials.<br>
<br>
I don't have any clear examples of this ( they are quite involved and would take an age to prepare so as to be easily understood ).<br>
<br>
The basic principles of this method is to supply a WORD document containing predefined bookamrks with data from an open recordset in ACCESS. <br>
<br>
You make the WORD available by creating an OLE instance of it ( Set oWord = CreateObject(&quot;Word.Basic&quot;) ) and then use WORD's VBA command set to open your document ( oWord.FileOpen &quot;your doc path&quot; ) and move between the bookmarks (oWord.editgoto &quot;Bookmark Name&quot; ) inserting the respective field data ( oWord.INSERT rst!Field1 ) from your open recordset as you go.<br>
<br>
When you have populated the document you can print it ( oWord.FilePrintDefault ). <br>
<br>
Finished with the word object ? Set it to Nothing ( Set oWord = Nothing )<br>
<br>
I don't know if this is more difficult than Doug's but it gives a good insight into the OLE power of the Office programs.<br>
<br>
Anyone got a good example of this ? DougP ?<br>
<br>
It is difficult to visualise this without example code<br>
<p>Bill Paton<br><a href=mailto:wpaton@neptune400.co.uk>wpaton@neptune400.co.uk</a><br><a href=
 
Well I always stick with what works. No I have not tried the OLE method.<br>
We started this procedure back in Access 2.0 (No I'm not still in 2.0. I use both '97 and 2000 now)<br>
It does work well (the Mail merge to an Access query) it may seem clumsy and I'll be the first to admit it can be slow unless &quot;Bucks&quot; are spent on FAAST hardware.<br>
Of course slow is relative.<br>
<br>
I guess our situation is that we needed data from 4 tables and a query was the easiest way to get that. We were using 75 fields in a 9 page Word doc.<br>
Today, I stay out of WORD and make Access do the whole thing.<br>
And because I sling VBA code around like seeds on the farm it doesn't take me long to whip out something.<br>
And this is worth mentioning too.<br>
One reason I have some answers so quick is because I have a whole folder of code snippets. They are text documents which have the file name of what it does. I open it, copy and paste the code in my application and go on the next thing.<br>

 
Hmmm.....

What is the difference between?

Set oWord = CreateObject(&quot;Word.Basic&quot;)

and

Set oWord = CreateObject(&quot;Word.Application&quot;)
 
Most things in life seem complicated or hard to understand in the beginning, but once you dived into the subject you realize that it is a piece of cake.

Following I explain from my subject point of view the whole Automation process (applicable to all programs that have an accessible object model) as comprehensive as possible (example Word):

Each and every action in WORD can be undertaken programmatically (via WORD-VBA).

The methods and properties are stored in a library file.
This file can be used by ACCESS-VBA.
How: just set a reference on the WORD-library file.

If you want to use one of the WORD-VBA components, just create a Word.object. Intellisense will show you the available methods and properties.

Once you understood the principle, two problems persist:

1.) You need to close and destroy the WORD-objects (easy).
2.) You need to learn WORD-VBA (at least the part you need for your work) (no so easy)

Side-effects:
-you will realize that other Office applications contain bugs, too.
- you will realize that non-Microsoft-Software contains even more bugs
 
Automation between Access 2000 and MS Word is actually pretty easy actually. There isn't much you can do to control Word from Access, but you can record or program macros and save them with a Word Template, export your report data to that Word template, and then run the macros to format your data so that it looks presentable. The following link shows you how to export data from Access 2000 to word:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top