**RESOLVED** Need Help With Adding Multiple Tables Into Word From Vb??
I need to know how I can write the code for multiple tables into Word...
The code I have is as follows:
VB Code:
On Error GoTo Error_Handler
Dim intNumofRows As Integer
Dim intNumofColumns As Integer
Dim p As Integer, ColWidth As Integer
Dim i As Integer
intNumofColumns = m_Recordset.Fields.Count
intNumofRows = m_Recordset.RecordCount
'Insert a new table with rows according to recordCount plus Column header
'and the number of columns in the recordset
wrdDoc.Tables.Add wrdSelection.Range, NumRows:=intNumofRows + 1, _
NumColumns:=intNumofColumns
iTableCounter = iTableCounter + 1
With wrdDoc.Tables(iTableCounter)
' Set the column widths
For i = 0 To intNumofColumns - 1
ColWidth = Len(m_Recordset.Fields(i).Name)
.Columns(i + 1).SetWidth ColWidth * 25, wdAdjustNone
.Cell(1, i + 1).Range.InsertAfter UCase(m_Recordset.Fields(i).Name)
Next i
' Set the shading on the first row to light gray
.Rows(1).Cells.Shading.BackgroundPatternColorIndex = wdGray25
' Bold the first row
.Rows(1).Range.Bold = True
' Center the text in Cell (1,1)
.Cell(1, 1).Range.Paragraphs.Alignment = wdAlignParagraphCenter
' Fill each row of the table with data
For i = 1 To intNumofRows
For p = 1 To intNumofColumns
FillRow i + 1, p, m_Recordset.Fields(p - 1)
Next p
p = 1
m_Recordset.MoveNext
Next i
End With
Set m_Recordset = Nothing
Exit Sub
Error_Handler:
Debug.Print Err.Description & " - " & Err.Number
This routine will be used to insert tables...the problem is that the liine of code ' wrdDoc.Tables.Add wrdSelection.Range' is being used more than once...When the 2nd table is being sent to the Word object the Debug.Print is saying that there is all ready a table in that location...
I need to find the code to have multiple table on the same document????
Thanks