Free Support Forum - aspose.com

If Condition MailMerge With VBScript/ASP

I want to insert a different field value depending on a value from another field into the Word document. I tried using Word's If Then Else field codes but that doesn't work. So how do I code it instead? I found this article which is the closest to the end result I want but that's different syntax than VBScript/ASP.
https://forum.aspose.com/t/129739


Here's my code so far:

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

Option Explicit
Dim RS
Dim Conn

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

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

Dim Doc
Set Doc = Word.Open("\\seagate-file\seagate\Sales & Marketing\Contract Documents\Sales Contracts\dbtest\CONTRACT CHECKLIST & TRANSACTION RECORD.doc")

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

Conn.Open "DSN=SeaGateContracts"

Set RS = CreateObject("ADODB.Recordset")

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

Doc.MailMerge.ExecuteWithRegionsADO RS, "qryMailMerge"

Doc.Save "\\seagate-file\seagate\Sales & Marketing\Contract Documents\Sales Contracts\dbtest\CONTRACT CHECKLIST & TRANSACTION RECORD NEW.doc"

%>






DONE

Hi,

Several options are possible here:

- Put the logic into the SQL query that returns it completely ready for mail merge;
- If you are mail merging one record only, it is a good idea to use DocumentBuilder.MoveToMergeField instead of MailMerge.Execute;
- Switch to .Net and use mail merge event handler.