Build Dynamically-Sized and Populated Word Table

david_johnson_CR

New member
Local time
Today, 05:59
Joined
Dec 5, 2017
Messages
7
Greetings,

I'm stumped on this one. I need to populate a Word document with, among other things, a table with simple data. I know how to use bookmarks and I know how to populate them from Access. What I don't know is what to do when the number of rows changes with each record.

How do I dynamically size the Word table and how do I populate that table with bookmarks? I'm open to other solutions as well. If I could build the table elsewhere and drop it into the right spot then, as long as it looks similar to this, that's fine.

Thanks for any help/guidance in advance!
David
 
Let's get clarification.

When you want to build a table, specifically what is the dynamic part?

If you have multiple rows in a table, NORMALLY each record would correspond to one row. So why is this different? Are you transposing rows and columns somehow? Your question is not clear because I don't "see in my mind" what you are using as a data source and further don't see how it relates to your required output.

Not to say we don't have answers here, but SOMETIMES we need a little bit more of the immediate details before we wade into the swamp.
 
Of course, my apologies for not being more clear. The way that I know to feed Access data into Word is through bookmarks. There may be another way but I am not familiar with it/them. So, because the size of the table (number of rows) is not fixed, I do not know how to use bookmarks to meet my firm's needs.

The number of rows is what I meant by dynamic. I am not familiar with a way to simply have Access add in another row to hold another record in a Word table, which is natural in Access. So, the crux of my problem/question is: how do I build a table in Word that can add rows as the number of records increases in my Access recordset and how do I tell Access/Word how/where to populate the data?

Thanks! Sorry for not being more clear initially.
 
Generally speaking if you export from a button into Word, with something like this.
Code:
DoCmd.OutputTo acOutputQuery, "[COLOR="Red"]qryHardwareExportWord[/COLOR]", acFormatRTF, "[COLOR="red"]BotHardware.rtf[/COLOR]", True
You will get a table in Word. Of course you need to use your own query and file names. First Define your query,
when you get the results your looking for export. The output will be rows of data in a table like grid.
 
Last edited:
IF you have bookmark in the Word document, then here is one trick.

Open a Word Application Object in a mode that will allow editing.

Open a copy of your template file (if that is what you are using).

Use the GoTo Bookmark operation within the Word App Object.

Insert a Word table at the bookmark. Presumably this is the first table.

Create an object for a Word Table and assign it (SET var = WordAppObj.Tables(0) since collections number from 0).

Add as many columns as you need up front. I.e. immediately after creating the table. Do it as soon as possible.

Now when you need to add a row, you do as static suggested. table-var.Rows.Add

Now, if you need to add data to an extant row to the table, it is something like

table-var.Rows(n).Cells(m) = "text value"

https://msdn.microsoft.com/en-us/library/kw65a0we.aspx - overview of Word document internal structure

https://msdn.microsoft.com/en-us/library/bb157878.aspx - page from which you can follow links regarding programmatic data management in a Word Table
 

Users who are viewing this thread

Back
Top Bottom