How to prevent table break , if the table size is below the word doc size.
ie if the table size is below word doc size dont spilt the table across
table, it has to shift to new page. if the table size is above doc it can
spilt. this is the code i used for creating table and writing data to it
here how many tables are there and where the table starts in docand how many
rows the there is known only after table is created..
Set rs2 = New ADODB.Recordset
oConnection_SQLserver.Open
rs2.Open "SELECT logTime, logType, Comment1,Comment2,logStatus FROM
TestEvent WHERE TestScriptID = " & lngTestScriptID & " AND TestCaseTime = " &
rs1(2).Value & " AND logType <> 5 ORDER BY logTime", oConnection_SQLserver,
adOpenStatic, adLockReadOnly
If (rs2.EOF = True) Then
GoTo ENDOFLOOP
End If
'Add a table to print the testevents.
rng.Tables.Add Range:=rng, NumRows:=2, NumColumns:=3
'enter the first row in the table
Set tbl = rng.Tables(1)
tbl.Cell(1, 1).Range.Text = "Action"
tbl.Cell(1, 2).Range.Text = "Results"
tbl.Cell(1, 3).Range.Text = "Test Result"
'expected Results flag is set to 1 on receiving a testevent with
logstatus equal to 1 or 3
expectedResultsFlag = 0
rowCount = 2
flagTestEventFail = False
'repeat for all testevents in each selected testcase
Do While (rs2.EOF = False)
'move to next row when expectedResultsFlag = 1
If (expectedResultsFlag = 1 And (rs2.Fields(1) = 0 Or
rs2.Fields(1) = 2)) Then
tbl.Rows.Add
rowCount = rowCount + 1
expectedResultsFlag = 0
flagTestEventFail = False
End If
'change the color to RED only if the testevent is Fail else
leave it as Black, which is default
If (rs2.Fields(4) = 0) Then
'case Fail
tbl.Cell(rowCount, 1).Range.Font.Color = wdColorRed
tbl.Cell(rowCount, 2).Range.Font.Color = wdColorRed
flagTestEventFail = True
Else
If (rs2.Fields(4) = 1 And flagTestEventFail = False) Then
'case Pass
tbl.Cell(rowCount, 1).Range.Font.Color = wdColorBlack
tbl.Cell(rowCount, 2).Range.Font.Color = wdColorBlack
flagTestEventFail = True
End If
End If
'Check the logstatus field
If (rs2.Fields(1) = 0 Or rs2.Fields(1) = 2) Then
'enter the testevent under the "Actions" column in the table
tbl.Cell(rowCount, 1).Range.InsertAfter (rs2.Fields(2) & " "
& rs2.Fields(3))
tbl.Cell(rowCount, 1).Range.InsertParagraphAfter
tbl.Cell(rowCount, 1).Range.SetRange tbl.Cell(rowCount,
1).Range.End, tbl.Cell(rowCount, 1).Range.End
ElseIf (rs2.Fields(1) = 1 Or rs2.Fields(1) = 3) Then
'enter the testevent under the "Expected Results" column in
the table
tbl.Cell(rowCount, 2).Range.InsertAfter (rs2.Fields(2) & " "
& rs2.Fields(3))
tbl.Cell(rowCount, 2).Range.InsertParagraphAfter
tbl.Cell(rowCount, 2).Range.SetRange tbl.Cell(rowCount,
2).Range.End, tbl.Cell(rowCount, 2).Range.End
expectedResultsFlag = 1
End If
rs2.MoveNext