Mail Merge Query - Please help

Hi, I have the following piece of code that I would like to enhance the SQL statement to invoke mail merge only if count of LtrTemp is greater than Zero (0). Please help

SQL1 = “SELECT * FROM Imported Data$
SQL2 = " WHERE (Imported Data$.Letter_Code=‘" & LtrTemp & "’)"

ActiveDocument.MailMerge.OpenDataSource Name:=offerdatafile, _
    ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
    AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
    WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
    Format:=wdOpenFormatAuto, Connection:=strConnection _
    , SQLStatement:=SQL1, SQLStatement1:=SQL2, SubType:= _
    wdMergeSubTypeOther

Regards,
Chris

SQL = “Select * from XYZDATA where XYZDATA.SOMETHING > 0”

Check this first to see if you get any records before going forward.

Then you can use ADO connection string to provide dataset.

Do while rst.eof = False

DO STUFF IN here

rst.movenext
Wend

etc…

Hi,

Thank you for your help. I tried the suggested code but it did not work.

Find attached the file used in my letter processing automation.

Kindly see if you can make it work.

Regards,
Almacjnr

??
Fishy??
??

Damski…either fishy or lazy…LOL!

Sorry to Almacjnr I don’t open up stray zip files from newbie users here. Now if someone in the senior level will vouch for you will see what we can do. You can also try www.planetsourcecode.com for possible help/source code sample starters.