Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Automated Mail Merge Help Needed!

Featured Replies

I have read all the mail merge threads and articles I could find, and I'm a little frustrated at the moment... I really hope someone could help me here!

I found a very simple approach to merging, which I've implemented, and the code is show below:

//OBJECT OF MISSING "NULL VALUE"
Object oMissing = System.Reflection.Missing.Value;

//OBJECTS OF FALSE AND TRUE
Object oTrue = true;
Object oFalse = false;
DataRow row;

//CREATING OBJECTS OF WORD AND DOCUMENT
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();

//DEFINE FILE
openFileDialog.ShowDialog();
openFileDialog.Filter = "Word Template File (*.dot)|*.dot|Word File (*.doc)|*.doc|All files (*.*)|*.*";

//SETTING THE VISIBILITY TO TRUE
oWord.Visible = true;

//THE LOCATION OF THE TEMPLATE FILE ON THE MACHINE
Object oTemplatePath = openFileDialog.FileName;

//ADDING A NEW DOCUMENT FROM A TEMPLATE
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

bs_results.MoveFirst();
row = ((DataRowView)bs_results.Current).Row;

foreach (Word.Field myMergeField in oWordDoc.Fields)
{
String fieldtext = myMergeField.Code.Text;

if (fieldtext.StartsWith(" NEXT"))
{
if (bs_results.Position == bs_results.Count-1) break;
bs_results.MoveNext();
row = ((DataRowView)bs_results.Current).Row;
myMergeField.Code.Text = String.Empty;
}

if (fieldtext.Contains("firstname"))
{
myMergeField.Select();
oWord.Selection.TypeText(row["firstName"].ToString());
}
if (fieldtext.Contains("lastname"))
{
myMergeField.Select();
oWord.Selection.TypeText(row["lastName"].ToString());
}
if (fieldtext.Contains("cellphone"))
{
myMergeField.Select();
oWord.Selection.TypeText(row["phoneCell"].ToString());
}
}

This is simple, and to the point, and works well. It has limitations though. It loops merge fields, so there are only so many labels created for example as are propagated in the .dot template file, as apposed to rows in the datatable.

My QUESTION:

How do I either propagate labels based on the row count, or do it completely different??

I basically have a results datatable with all the data I need, and would like to mail merge that data to labels in a Word template.

Any help would be appeciated! PLEASE!


Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.