Aspose words MailMerge.ExecuteWithRegionsADO comhelper vb6

Hi
I am very new to aspose words so please bear with me. This will hopefully have a straightforward answer which i just cant seem to find:

We have an invoice table and invoiceItems table in sqlserver2012.
We use vb6 with ADO and are using comHelper

The mailmerge template has been setup. There are mailmerge fields in the header footer and body of the document and there is a table for the invoiceItems (this region has been defined by TableStart:invoiceLines and TableEnd:invoiceLines).

Set rsInv = cn.Execute(“select * from invoices where invoiceid=452275”)
Set rsInvLines = cn.Execute(“select * from invoicelines where invoiceid=452275 order by orderNo”)
'Create DocumentHelper
Dim helper
Set helper = CreateObject(“Aspose.Words.ComHelper”)
'Open template document
Dim Doc
Set Doc = helper.Open(“c:\test.doc”)
Doc.MailMerge.ExecuteWithRegionsADO rsInvLines, “InvoiceLines”
Doc.MailMerge.ExecuteWithRegionsADO rsInv, “Invoice”
Doc.Save (“C:\out.doc”)

I am confused as the ADO recordset doesnt store the Parent-Child relationship. So do I call the ExecuteWithRegionsADO twice as per the example above where the data recordsets contain data from one table each?
In any case, how can i define the Invoice region if it starts in the header and ends in the footer. I got the error message saying they needed to be in the same part of the document or table, as I had put <TableStart:Invoice> in the header at the beginning of the document and <TableEnd:Invoice> at the end of the last footer.

I can get the InvoiceLines section to merge with just this line:
Doc.MailMerge.ExecuteWithRegionsADO rsInvLines, "InvoiceLines"

I can get the main document including the headers to merge by not defining the Invoice region and using:

Doc.MailMerge.ExecuteADO rsInv


Questions:
1. How best to form the ADO recordset (as two recordsets or as one)
2. How best to merge into the header, footer and body at the same time.

Sorry for rambling but i hope its clear what i am trying to achieve. Thanks for your (speedy!) help


Asif


Hi Asif,

Thanks for your inquiry.

asifh:

I am confused as the ADO recordset doesnt store the Parent-Child relationship. So do I call the ExecuteWithRegionsADO twice as per the example above where the data recordsets contain data from one table each?
1. How best to form the ADO recordset (as two recordsets or as one)

MailMerge.ExecuteWithRegionsADO method performs mail merge from an ADO Recordset object into the document with mail merge regions. This method is useful when you intend to use Aspose.Words classes as COM objects from unmanaged code such as an application built using ASP or Visual Basic 6.0.

For more information see description of MailMerge.ExecuteWithRegions(DataTable).

You can call the ExecuteWithRegionsADO method for each region in your template. This method does not support parent-child (master-detail) data sources and nested mail merge regions. I suggest you please read following documentation link for your kind reference.
http://www.aspose.com/docs/display/wordsnet/Use+Aspose.Words+for+.NET+via+COM+Interop
asifh:

In any case, how can i define the Invoice region if it starts in the header and ends in the footer. I got the error message saying they needed to be in the same part of the document or table, as I had put <TableStart:Invoice> in the header at the beginning of the document and <TableEnd:Invoice> at the end of the last footer.
2. How best to merge into the header, footer and body at the same time.

Please read the simple rules when marking a region from here:
http://www.aspose.com/docs/display/wordsnet/Mail+Merge+with+Regions+Explained

It would be great if you please share your template document along with expected output document here for our reference. We will then provide you more information about your query.

Thank you - i have read all those but still at a loss as to how to deal with headers and footers and the data recordset (i am using vb6).

I attach the template so you can advise on how to set up the regions. The document also has text boxes that contain mergefields.

Do i need to set up two data recordsets (there is no Dataset in vb6)?

thanks

Hi Asif,

Thanks for your inquiry. In your case, you need to create three ADO Recordset objects.

1) Create Recordset object for header/footer mail merge fields. In this case, please use MailMerge.ExecuteADO method (mail merge without regions). For more information see description of MailMerge.Execute(DataTable).

2) Create Recordset object for Invoice and use MailMerge.ExecuteWithRegionsADO method

3) Create Recordset object for InvoiceLines and use MailMerge.ExecuteWithRegionsADO method

Hope this helps you. Please let us know if you have any more queries.

This worked

Thank you


Hi Asif,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.