C# - MS Word - MailMerge how to get Last Record when MailMerge.DataSource.LastRecord returns -16 -
unable last record using mailmerge.datasource.lastrecord
or mailmerge.datasource.recordcount
first variable returns -16 , second 1 returns -1.
cause: .lastracord
, .recordcount
returning -16 , -1 because reading data csv file.
solution: following code return last record or record count reading dataset csv file or text file.
public int getmailmergelastrecord() { document doc = globals.addin.activedocument; // storing current record int currentrec = (int)doc.mailmerge.datasource.activerecord; //getting last record int lastrecord = 1; doc.mailmerge.datasource.activerecord = (doc.mailmerge.datasource.activerecord - (int)doc.mailmerge.datasource.activerecord) + int32.maxvalue; lastrecord = (int)doc.mailmerge.datasource.activerecord; // resetting current record above line of codes change active record last record. doc.mailmerge.datasource.activerecord = (doc.mailmerge.datasource.activerecord - (int)doc.mailmerge.datasource.activerecord) + currentrec; return lastrecord; }
note
above code word application level addin
Comments
Post a Comment