Cannot insert the requested break inside a table

Hi,
I have the following bit of code whish i believe is supposed to set the document into 2 columns, where the mergeField is, insert some text and then insert a column break to start writing at the top of the next column. Unfortunately i get the above error. The 2 columns are only supposed to be where the merge field is, not the whol page / document.

builder.MoveToMergeField("InsuringClauses");
// Split into 2 columns
builder.PageSetup.TextColumns.SetCount(2);
if (dtResult.Rows.Count > 0)
{
    for (int i = 0; i <= dtResult.Rows.Count - 1; i++)
    {
        builder.StartTable();
        // some builder.writeln etc stuff
        if (clauseCounter == 6)
        {
            builder.EndTable();
            builder.InsertBreak(BreakType.ColumnBreak);
        }
    }
}

You can see i close the table. Any ideas?

Hi
Thanks for your inquiry. The 2 columns should be in the section where the merge field is. Your document contains few sections. Could you please attach your template for testing and create the document that will show me how the output should looks?
Best regards.

Hi
Thanks for your inquiry. I think that you should insert section break before and after inserting content in two columns. Please try using the following code:

Document doc = new Document(@"Test012\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToMergeField("InsuringClauses");
// Insert Section break
builder.InsertBreak(BreakType.SectionBreakContinuous);
// Set columns count
builder.CurrentSection.PageSetup.TextColumns.SetCount(2);
builder.Writeln("//something//");
builder.InsertBreak(BreakType.ColumnBreak);
builder.Writeln("//something//");
// Insert section break
builder.InsertBreak(BreakType.SectionBreakContinuous);
// Reset columns count
builder.CurrentSection.PageSetup.TextColumns.SetCount(1);
doc.Save(@"Test012\out.doc");

Best regards.

Thanks. But i now get the following error. Mail merge region ‘BasicDetails’ is badly formed. TableStart and TableEnd should be in same section, same table row or same table cell.
I can’t see anything wrong. Please find my document attached. Just to note, i am using MailMerge.ExecuteWithRegions as i am also passing a dataset to the document when i am performing the mailmerge.

Hi
Thanks for your inquiry. You should insert section breaks during mail merge. You should use MErgeField event handler to achieve this. Please see the following code:

public void Test012()
{
    // Create some datasource
    DataTable tab = new DataTable("BasicDetails");
    tab.Columns.Add("CertTitle");
    tab.Columns.Add("CertificateNumber");
    tab.Columns.Add("AssuredName");
    tab.Columns.Add("AssuredAddress");
    tab.Columns.Add("InceptionDate");
    tab.Columns.Add("ExpiryDate");
    tab.Columns.Add("GrossPremium");
    tab.Columns.Add("IPT");
    tab.Columns.Add("IPTAmount");
    tab.Columns.Add("OpInsClauses");
    tab.Columns.Add("InsuringClauses");
    // Add some data to datasource
    for (int i = 0; i < 5; i++)
    {
        tab.Rows.Add(new object[] { "CertTitle", "CertificateNumber", "AssuredName", "AssuredAddress", DateTime.Now, DateTime.Now, 100, 100, 100, "OpInsClauses", "InsuringClauses" });
    }
    // Open template 
    Document doc = new Document(@"Test012\in.doc");
    // Add MergeField event handler
    doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField012);
    // Execute mail merge
    doc.MailMerge.ExecuteWithRegions(tab);
    // Save result document
    doc.Save(@"Test012\out.doc");
}
void MailMerge_MergeField012(object sender, MergeFieldEventArgs e)
{
    if (e.FieldName == "InsuringClauses")
    {
        DocumentBuilder builder = new DocumentBuilder(e.Document);
        builder.MoveToMergeField(e.FieldName);
        // Insert Section break
        builder.InsertBreak(BreakType.SectionBreakContinuous);
        // Set columns count
        builder.CurrentSection.PageSetup.TextColumns.SetCount(2);
        builder.Writeln("//something//");
        builder.InsertBreak(BreakType.ColumnBreak);
        builder.Writeln("//something//");
        // Insert section break
        builder.InsertBreak(BreakType.SectionBreakContinuous);
        // Reset columns count
        builder.CurrentSection.PageSetup.TextColumns.SetCount(1);
    }
}

Hope this helps.
Best regards.