2

CODE:

public void Print(string docLoc, string docSource)
        {
            try
            {
                Word.Application oWord = new Word.Application();
                Word.Document oWrdDoc = new Word.Document();
                oWord.Visible = true;
                Object oTemplatePath = "C:\\Users\NAME\\Desktop\\B-AIAddChgDual10-06-NEW.doc";
                oWrdDoc = oWord.Documents.Open(oTemplatePath);
                Object oMissing = System.Reflection.Missing.Value;
                oWrdDoc.MailMerge.OpenDataSource("C:\\Users\\NAME\\Desktop\\Test2.txt", oMissing, oMissing, oMissing,
                    oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                oWrdDoc.MailMerge.Execute();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Source:\t" + ex.Source + "\nMessage: \t" + ex.Message + "\nData:\t" + ex.Data);
            }
            finally
            {
                //
            }
        }

When I process the above my Application Instance opens saying I'm locked out of the file because I myself am using it??? After I accept to open a Read-Only copy, I receive the following (in order):

Reult Dialog1 Dialog2 Dialog3 Dialog4 Dialog5 Dialog6 Dialog7

After selecting how to replace the fields in the above:

Merge Errors

Original Mail Merge Fields:

enter image description here

After Personal Selections:

enter image description here

How do I tell the Word Application to use the '!' character as the Field Delimiter in my C# code?

Also, how do I proceed with the dialogs? I'm assuming I receive each one due to my datasource not containing fields matching those listed as Mail Merge Fields?

Here are my Mail Merge Fields:

-fuldate -sys -memno -name -address1 -address2 -address3 -sal

And here are my Delimited fields from my .txt DataSource file:

memno!name!addr1!addr2!city!state!zip!old_addr1!old_addr2!old_city!old_state!old_zip

Analytic Lunatic
  • 3,853
  • 22
  • 78
  • 120

1 Answers1

0

To Solve this issue i think you need to create 3 Merge Feilds: as below :

  formLetterDatas=>  MergeField1    [DUMMY_FIELD]
                          Data1           NULL
                          Data2           NULL
                          Data3           NULL

// Create a MailMerge Data file.
CreateMailMergeDataFile(tableHeader, formLetterDatas);

Please see this Link Word Mail Merge Bypass Header Record Delimiters Popup

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
  • Thanks for the link! :) But the thing is I'm not, nor in this instance ever, going to be dealing with a single merge field. I think I figured out how to resolve all the dialogues except the first one with the Record Delimiters dialogue as mentioned in the link. How would I bypass when I already have 8 Merge fields in the document? – Analytic Lunatic Nov 14 '13 at 20:51
  • Having some respect for the people who have been putting effort in on your behalf might help, "Analytic Lunatic". It's blindingly obvious that Word hasn't recognised "!" as a field delimiter in this case. –  Nov 14 '13 at 21:25
  • @bibadia, I meant no disrespect whatsoever and I apologize if things came across that way. I was simply saying the article appears to be digressing over a Mail Merge with a singular field, which is not the case for what I'm doing in this instance. Still an interesting article ^^ I don't understand how Word doesn't recognize "!" as a field delimiter though, since it IS available in the dropdown for Delimiter Selection? – Analytic Lunatic Nov 14 '13 at 21:56
  • Actually it was the succession of questions, one with comments that you hadn't responded to or apparently taken any notice of, that I was referring to. The problem here is likely caused by the fact that you have two different candidate delimiters in your data (!) and (_). If you are in a position to remove the _, I would at least try that. But that is why I mentioned in my comments to your earlier message that you should consider "wrapping up" your text data, esepcially if, e.g., a comma character can appear in your address data. –  Nov 15 '13 at 16:05