in my Access VBA I have the following creating and populating a Word Table without issue.
oWord.ActiveDocument.Tables.Add Range:=oDoc.Bookmarks("\endofdoc").Range, NumRows:=1, NumColumns:=5
rs.MoveFirst
r = 0 'current row counter
'start the recordset loop reserving the top two rows for header type stuff.
With oWord.Selection
.TypeText "Control Identifier"
.MoveRight Unit:=wdCell
.TypeText "Control Name"
.MoveRight Unit:=wdCell
.MoveRight Unit:=wdCell
.MoveRight Unit:=wdCell
'first data row
.MoveRight Unit:=wdCell
.TypeText rs("Control_Main")
.MoveRight Unit:=wdCell
.TypeText rs("Title")
.MoveRight Unit:=wdCell
.MoveRight Unit:=wdCell
.MoveRight Unit:=wdCell
......
and so on when the table is completed I insert a page break and some text, then I insert a second table.
oWord.ActiveDocument.Tables.Add Range:=oDoc.Bookmarks("\endofdoc").Range, NumRows:=1, NumColumns:=3
rs.MoveFirst
With oWord.Selection
'first data row
.MoveRight Unit:=wdCell
.TypeText rs("Control_main")
.MoveRight Unit:=wdCell
.TypeText rs("Title")
.MoveRight Unit:=wdCell
......
The second table gets created but nothing populates in it. If I put oWord.Selection.Style = "Table Grid"
after my second table creation - it creates a grid around the first table but no additional text or rows are added to the first table.
I know I can do a set oTable =
type of table creation, but then when I try and select it, it seems to select from the Word.Document instead of the Word.Application and my subsequent with .Selection doesn't act right for .moveright for my dynamic creation.
Any ideas where i'm going awry?
---Update post working --- A very special thank you to @freeflow for his patience and assistance. His code was great, I just needed to do a slight tweak mainly with this part. ... The move unit wdRow worked, but without the additional row it exited the table. I also had problems with referring to .Cells(2) for 2nd column in that row - but moving first then entering text worked just fine.
this.
myRow.Move unit:=wdRow, Count:=1
myRow.Cells(1).Range.Text = rs("Control_Main")
myRow.Cells(2).Range.Text = rs("Title")
became this.
oDoc.Tables(1).Rows.Add
myRow.Move Unit:=wdRow, Count:=1
myRow.Cells(1).Range.Text = rs("Control_main")
myRow.Move Unit:=wdCell, Count:=1
myRow.Cells(1).Range.Text = rs("Title")