Creating and loading a table

B

bryan

Not sure if I should use a table or what.
What I want to do is create and load fields with data which is in an array
which was selected from a listbox.
When users create a doc from this template, some info is loaded into form
fields from our host system. The user is then presented with a listbox where
they can select as many entries as they wish. I want to position all these
slections on the document after the 3rd paragraph in such a way as 3 entries
per line with a bullet in front of each if possible.
My first thought was to use a formfield and use a vb tab and vb chr but, not
sure how to do this either or if that would line them up correctly.
An example of what I want:
Paragraph1....
Paragraph2....
Paragraph3....
Entry1 Entry2 Entry3
Entry4 Entry5 Entry6
Etc.
Paragraph4.....

Thanks in advance,
Bryan
 
D

Doug Robbins - Word MVP

I would suggest that you use a four column table, starting with a one row
table in the template from which you are creating the document and with a
bulleted paragraph in the first column of the table (the paragraph can be
empty, and you can remove the borders from the table so that it will look
like the data that is entered into columns two, three and four are part of a
bulleted list (except for the spacing between those columns) Then you would
iterate through the data to be inserted, adding a new row to the table for
the second and subsquent pieces of data. With the bulleted paragraph in the
first row, you will automatically get a bulleted paragraph in the first cell
of each new row.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

bryan

Hi Doug,
Let's say I have created the table, 1 row and 3 columns ( I'm assuming I add
formfields within, Correct?.
Upon new doc, lets' say I select 7 entries from the listbox. In iterating
through those, I would populate the first 3 formfields of the table.
How do I insert new rows on this table if I may have another table on the
form?
Once I have inserted this row or rows depending on the number of entries,
how do I know the formfield name to which to populate?
Do I rename them?

I appreciate the help,
Bryan

I am getting better at understanding the coding of macros but, always
something new - which is good.....
 
D

Doug Robbins - Word MVP

I am assuming that there are 3 columns (columns1, 2 and 3) and that your
listbox is ListBox1, you would use the following code:

Dim i As Long, j As Long, k As Long
Dim atable As Table
Dim arow As Row
Set atable = ActiveDocument.Tables(1)
k = 1
With ListBox1
For i = 0 To .ListCount - 1
'..and check whether each is selected
If ListBox1.Selected(i) Then
If k = 1 Then
Set arow = atable.Rows(1)
k = k + 1
Else
Set arow = atable.Rows.Add
End If
For j = 0 To 2
arow.Cells(j + 1).Range.Text = .List(i, j)
Next j
End If
Next i
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

bryan

From this it looks like I would not need to add form fields into the table
cells then, correct?
If no form fields wouldn't I need to unprotect my template before doing any
of this and then protecting again?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top