Free Support Forum - aspose.com

Merging More Than One Doc

For some reason when I try to merge more than one doc in a set of code, all docs after the first do not merge. When I make the second doc the first doc in the code it works. I'm just trying to use the same recordest over and over for each doc. Can you not do that? Here's the code:

<%@ LANGUAGE="VBSCRIPT" %>
<%

Option Explicit
Dim qryMailMerge
Dim qryMailMerge2
Dim qryAdditionalDeposit
Dim Conn
Dim JobNum
Dim CurrentUser
Dim Doc
Dim Word

Set Word = CreateObject("Aspose.Word.Word")

Word.SetLicenseCOM "C:\Inetpub\wwwroot\Aspose.Word\License\Aspose.Word.lic.txt"

JobNum = Request.QueryString("JobNum")
CurrentUser = Request.QueryString("CurrentUser")

Set Conn = Server.CreateObject("ADODB.Connection")

Conn.Open "DSN=SeaGateContracts"

Set qryMailMerge = CreateObject("ADODB.Recordset")

qryMailMerge.Open "SELECT * FROM qryMailMerge WHERE JobNum = '" & JobNum & "'", Conn


Set Doc = Word.Open("\\seagate-file\seagate\Sales & Marketing\Contract Documents\Sales Contracts\SalesDB\LOT AQUISITION Addendum.doc")

Doc.MailMerge.ExecuteADO qryMailMerge

Doc.Save "\\seagate-file\seagate\Sales & Marketing\Contract Documents\Sales Contracts\SalesDB\" & CurrentUser & " LOT AQUISITION Addendum.doc"


Set Doc = Word.Open("\\seagate-file\seagate\Sales & Marketing\Contract Documents\Sales Contracts\SalesDB\ABA Disclosure -First Rate Home Mortgage.doc")

Doc.MailMerge.ExecuteADO qryMailMerge

Doc.Save "\\seagate-file\seagate\Sales & Marketing\Contract Documents\Sales Contracts\SalesDB\" & CurrentUser & " ABA Disclosure -First Rate Home Mortgage.doc"
%>
DONE

Once you merge into the document once - the merge fields are gone and merging into the same document again will not change it.

You need to either open the document file everytime before you merge or open it once and Document.Clone() every time before you merge into it.

I’m not merging the same document over and over, I’m opening and trying to merge a different document.

What happens inside Aspose.Word mail merge engine is that the ADO recordset is converted into ADO.NET DataTable using code like this:

private static DataTable RecordsetToTable(object recordset)

{

System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter();

DataTable table = new DataTable();

adapter.Fill(table, recordset);

return table;

}

Maybe it uses MoveNext, EOF on the ADO Recordset and thus your ADO recordset stays at EOF after first mail merge operation. Try MoveFirst or what is the appropriate method in ADO recordset I don’t remember.

I had the same issue as lited above. I'm allowing users to merge one recordset to multiple documents at one time. the MoveFirst option didn't work.

I found that the problem was reusing the recordset. You have to get a new recordset for this to work. Cloning (rs.Clone) your recordset will not work either.

Cheers.