UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> How To Populate A Word Table, Office 2007    
 
   
bizhelp9
post Nov 20 2017, 12:25 AM
Post#1



Posts: 528
Joined: 19-November 08
From: Chicago


Hi,

I want to populate a table in Word with information from a query in Access.

I don’t know how many records I will have in my query, but I know that there will be at least one record.

I have a “template” word document which has the table with one row. The first cell of the table has a bookmark in it.

My table looks like this:

Child First Name Child Last Name Child Age Child Gender Christmas Gift Ideas
Bookmark: Child_FirstName

I’m thinking that I need to do something like this:

Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs2 As DAO.Recordset

Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open("C:\Path\Document_with_table.docx")
Set rs2 = CurrentDb.OpenRecordset("qry_ChildrenByFamily")

If Not rs2.EOF Then rs.MoveFirst

Do Until rs2.EOF
wDoc.Bookmarks("Child_FirstName ").Range.Text = Nz(rs2!CaregiverFirstName, "")

Then I need to something like advance to the next cell and do the following (How do I do this?)
Populate cell with Child Last Name (How do I do this?)

Advance to next cell (How do I do this?)
Populate cell with Child Age (How do I do this?)

Advance to next cell (How do I do this?)
Populate cell with Child Gender (How do I do this?)

Advance to next cell (How do I do this?)
Populate cell with Christmas Gift Ideas (How do I do this?)

If not rs2.EOF Then
Do something like tab to create a new row in the table. (How do I do this?)
rs2.MoveNext
Go back to statements above and populate the next row of the table

str_FileName = "C:\Path to where I want to save the updated document\ "Name_of_NewDocument.docx"

wDoc.SaveAs2 str_FileName


Thank you,

Dave
Go to the top of the page
 
JonSmith
post Nov 20 2017, 07:13 AM
Post#2



Posts: 3,160
Joined: 19-October 10



Working with 2007 limits you somewhat. If you had Word 2013 or higher they have repeating content controls which makes tables super easy with some XML data.
Can you ditch the unsupported software and upgrade?
Go to the top of the page
 
bizhelp9
post Nov 20 2017, 11:03 AM
Post#3



Posts: 528
Joined: 19-November 08
From: Chicago


Thank you John.

Unfortunately, I will have to work with Access 2007 for this project.

I believe there is a way to execute Word controls through Access VBA, but I don't know how to do that.

Please offer any suggestions.

Dave
Go to the top of the page
 
JonSmith
post Nov 20 2017, 11:49 AM
Post#4



Posts: 3,160
Joined: 19-October 10



There is but I don't have any examples and its a pain to do with bookmarks and iterating through table cells.
Hopefully someone else will chime in with a demo.

JS
Go to the top of the page
 
bizhelp9
post Nov 20 2017, 08:58 PM
Post#5



Posts: 528
Joined: 19-November 08
From: Chicago


Thank you JS.

I would appreciate if anyone else has any suggestions.

Dave
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    15th December 2017 - 03:19 AM