Something wrong in this code

M

Miguel

Hi, I'm trying to do a mailmerge with Word XP. I want to do a selection of
records, this mean, a query with sentence "WHERE".

I'm using a file .ODC for data source, where are all tables from the
database (Sql Server 2k).

Some idea?

object sqlstament = "Select * from CR_Datos";

wrdMailMerge.OpenDataSource2000(OrigenDatos+"\\homeDAT.odc",ref oMissing,ref
oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref
oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref
sqlstament,ref oMissing);

wrdMailMerge.DataSource.QueryString = " WHERE field1 < 100";

wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;

wrdMailMerge.Execute(ref oFalse);
 
B

Bruno Jouhier [MVP]

You need to execute the full SELECT statement, not just the WHERE clause:

wrdMailMerge.DataSource.QueryString = "SELECT * from CR_Datos WHERE field1 <
100";
 
M

Mystery Man

Hi Miguel

I think the QueryString line should read:

wrdMailMerge.DataSource.QueryString += " WHERE field1 < 100";

I tried on a CSV and this all works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top