Hello all,
I've posted this question before, but did not get an answer.
But the problem still exists, so..... I give it another try.
I want to insert a serie of tables in the middle of an existing
word-document and want a pagebreak after each table.
I try to do this by replacing a bookmark. See the code below:
But when I do it this way I will first see all pagebreaks and after them all
tables without pagebreaks.
I have tried all kinds of other solutions but nothing seems to do the job.
Can you give me a hint how to solve this?
Regards,
Jan Janson
function Make_Merge_Table_Model_I4(iWord: WordApplication; iDocument:
WordDocument; cBookmark: string): boolean;
var
nRow,nRows: Integer;
iRange: Range;
iTable: array of Table;
nTable: Byte;
ovBM: OleVariant;
ovBreakKind: OleVariant;
ovDirection: OleVariant;
begin
with dmElection do begin
ovBM := cBookmark;
{select range of bookmark}
iRange := iDocument.Bookmarks.Item(ovBm).Range;
iRange.Select;
nTable := 0;
tblFPart.First;
while (not tblFPart.eof) do begin
Inc(nTable);
SetLength(iTable,nTable);
nRows := tblFPartCANDIDATES.Value;
{add table}
iTable[nTable-1] := iWord.ActiveDocument.Tables.Add(iRange,nRows,3);
{fill table}
nRow := 0;
tblFKand.Locate('PARTY',tblFPartPARTY.Value,[]);
while (not tblFKand.eof) and (tblFKandPARTY.Value=tblFPartPARTY.Value)
do begin
Inc(nRow);
iTable[nTable-1].Cell(nRow,1).Range.Text := tblFKandCAND_NO.Value;
iTable[nTable-1].Cell(nRow,2).Range.Text := tblFKandNAME.Value;
iTable[nTable-1].Cell(nRow,3).Range.Text := tblFKandCITY.Value;
tblFKand.Next;
end;
{Collapse to end}
ovDirection := wdCollapseEnd;
iRange.Collapse(ovDirection);
{insert pagebreak}
ovBreakKind := wdPageBreak;
iRange.InsertBreak(ovBreakKind);
tblFPart.next;
end;
end;
end;