mdnuts
Registered User.
- Local time
 - Today, 08:29
 
- Joined
 - May 28, 2014
 
- Messages
 - 131
 
Kind of odd.  I have the following code creating a table inside of another table's cell.   What is intended to happen is the first table writes a few rows out, then when it gets to a particular cell, it then creates the nested table and starts to populate it.  When that's complete, the first table resumes populating  and inserting, and so on.
First table works fine, but with the nested table - the table itself is created fine. If I watch the document being populated, I see each row being populated correctly. When it advances a row, the previous rows' text disappears. the only text that remains is the last set of text for that table. The main table resumes doing it's own thing just fine.
When I debug.print the values are correct and match what I initially see on the word table being printed.
I can understand this happening if I was inserting and removing rows but that's not the case here. Can anyone see something i'm missing?
	
	
	
		
 First table works fine, but with the nested table - the table itself is created fine. If I watch the document being populated, I see each row being populated correctly. When it advances a row, the previous rows' text disappears. the only text that remains is the last set of text for that table. The main table resumes doing it's own thing just fine.
When I debug.print the values are correct and match what I initially see on the word table being printed.
I can understand this happening if I was inserting and removing rows but that's not the case here. Can anyone see something i'm missing?
		Code:
	
	
	      'here we are checking and inserting any applicable inheritances - or a second related table.
      r2 = 0 'start off at first table row
      sSQL2 = "Select qryInheritance.Control, qryInheritance.AP_Acronym, qryInheritance.CCI_Number, qryInheritance.Inheritable_Status, qryInheritance.Via from qryInheritance where qryInheritance.Control='" & fldControlMain & "' and Inheritable_Status='Inheritable' order by ID asc;"
      Set rs2 = db.OpenRecordset(sSQL2)
      If rs2.EOF Then
       'well shucks
      Else
        rs2.MoveLast
        rs2.MoveFirst
        strRowCount2 = rs2.RecordCount + 1
        Do Until rs2.EOF
          'set the variables from the table fields
          Set fldAP = rs2.Fields("AP_Acronym")
          Set fldCCI = rs2.Fields("CCI_Number")
          Set fldVia = rs2.Fields("Via")
          
          r2 = r2 + 1 'advance a row
          'here we are inserting a table 3 columns wide into this particular cell.
          'first we set a bookmark to indicate where we want the table to be
          ActiveDocument.Bookmarks.Add Name:="Inherit_" & r, Range:=oDoc.Tables(1).Cell(r, 2)
          Set oTable2 = oDoc.Tables.Add(oDoc.Bookmarks("Inherit_" & r).Range, strRowCount2, 3)
          ActiveDocument.Bookmarks(Index:="Inherit_" & r).Delete
          
          'start to populate the table
          If r2 = 1 Then 'header row
            Debug.Print fldControlMain & " - " & r2 & " - Yes"
            oTable2.Cell(r2, 1).Range.Text = "AP"
            oTable2.Cell(r2, 2).Range.Text = "CCI"
            oTable2.Cell(r2, 3).Range.Text = "Inherited By"
          End If
          
          Debug.Print fldControlMain & " - " & fldAP & " - " & fldCCI & " - " & fldVia
          oTable2.Cell(r2, 1).Range.Text = fldAP
          oTable2.Cell(r2, 2).Range.Text = fldCCI
          oTable2.Cell(r2, 3).Range.Text = fldVia
          
        rs2.MoveNext
        Loop
      End If
      'here is where we would be checking and inserting enhancements.
      r2 = 0