Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sending data to Word template

Posted on 2009-02-12
9
Medium Priority
?
647 Views
Last Modified: 2012-05-06
Experts,

Here is my scenario:

I have an Access database. With the push of a button, I would like to be able to open a new Word document based on an existing Word template and auto-populate it with data from my database. After the document is filled out, the data needs to save back to the database.

I know this can be easily done with an Access form, but I was informed that I would have to utilize Word templates. Any help is appreciated.
0
Comment
Question by:MarkRod
  • 4
  • 3
  • 2
9 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 23627775
Sounds a bit pointless, but not too difficult if the templates a for Word forms documents.
Sub ToAndFromDoc()
    Dim wdApp As Word.Application 'early binding, so needs to have a reference to the Word object library.
    Dim wdDoc As Word.Document
    Dim rs1 As New ADODB.Recordset
    Dim rs2 As New ADODB.Recordset
    
    Set wdApp = CreateObject("Word.Application")
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Add("C:\MyTemplates\Mytemplate.dot")
    rs1.Open "MyTable1", CurrentProject.Connection
        wdDoc.FormFields("Text1").Result = rs1.Fields("Field1").Value
        '... other fields
    rs1.Close
    rs2.Open "MyTable2", CurrentProject.Connection
        rs2.AddNew
        rs2.Fields("Field1").Value = wdDoc.FormFields("Text1").Result
        '... other fields
        rs2.Update
    rs2.Close
    wdDoc.Close wdDoNotSaveChanges
    wdApp.Quit
End Sub

Open in new window

0
 
LVL 11

Expert Comment

by:donaldmaloney
ID: 23628634
Following up on what Graham wrote.
Mark,

Just a Q.
Why do you "have to utilize Word templates?"  Those highher up need to use them?

Since you are in the Access DB.  open a form, populate the info, collect the new info and generate a report or export a rtf. (which can be read in word)

Plus if you need to go back in time just set a date/time index on your records.

The ONLY time I use Word or Excel from Access is to IMPORT data   then I append to my tables and am off and running.

Don
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MarkRod
ID: 23633231
To answer your question, I believe I have to use the Word templates so I do not have to re-create the form in Access.
0
 

Author Comment

by:MarkRod
ID: 23633268
Graham,

How do I know/set the field names in the template that will be used for this line of code?
wdDoc.FormFields("Text1").Result = rs1.Fields("Field1").Value

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 23634907
If you are, in fact, using a forms document, you can find the form field names unprotecting the document, right-clicking on the field, choosing Properties, and noting the bookmark name.

Obviously you will have to match individual table fields with document fields with your own knowledge of the document and the data.

Note. Show the Forms toolbar to help with work on forms documents.
0
 
LVL 11

Expert Comment

by:donaldmaloney
ID: 23635109
sorry try this one:  (I cut off the L at the end)

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21200618.html

Don
0
 
LVL 11

Expert Comment

by:donaldmaloney
ID: 23635278
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question