Something wrong in this code

  • Thread starter Thread starter Miguel
  • Start date Start date
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);
 
You need to execute the full SELECT statement, not just the WHERE clause:

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

I think the QueryString line should read:

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

I tried on a CSV and this all works
 
Back
Top