none
How to check if MailMerge.DataSource.DataFields(n).Value returns value without error?

    Question

  • I am writing my own handler on MailMergeBeforeMerge.

    On some of DataFields I get an error and can't get a value.

    Is there any way to programmatically check if MailMerge.DataSource.DataFields(n).Value would return a value?
    I tried IsNull(MailMerge.DataSource.DataFields(n)) but MailMerge.DataSource.DataFields(n) is not null, and still MailMerge.DataSource.DataFields(n).Value causes an error.
    Thursday, November 10, 2011 12:16 PM

Answers

  • ActiveDocument.MailMerge.DataSource.DataFields(n).Value
    where n is a string or integer variable.

    Presumably, you're actually using something like:

    Have you confirmed that the referenced datafield (name or index number) exists (eg not a mis-typed name or a number out of range)?
    Do you get an error for every record with this datafield, or only for some records?
    Does it work correctly for all other datafields?


    Hi

    I had the same problem while browsing throw data fields in debugger.

    But I finally solved the problem:

    Mail Merge data was produced by MS Dynamics CRM 4.0

    And some Merge Field names were too long. I threw out ONE last symbol from merge field names and its now OK.

    Tuesday, November 15, 2011 9:53 AM

All replies

  • Hi,

    It seems Code for develop,  In order to get the answer effectively, it is recommended to post a new thread in Microsoft Office for Developer Forum for further discussion.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.  

    More reference "MailMergeDataFields Collection Object", hope this helpful.

    http://msdn.microsoft.com/en-us/library/aa223028(v=office.11).aspx

    Best regards

    William Zhou
    --------------------------------------------------------------------------------
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 15, 2011 7:12 AM
    Moderator
  • I am writing my own handler on MailMergeBeforeMerge.

    On some of DataFields I get an error and can't get a value.

    Is there any way to programmatically check if MailMerge.DataSource.DataFields(n).Value would return a value?
    I tried IsNull(MailMerge.DataSource.DataFields(n)) but MailMerge.DataSource.DataFields(n) is not null, and still MailMerge.DataSource.DataFields(n).Value causes an error.


    hi Andrey,

    Presumably, you're actually using something like:
    ActiveDocument.MailMerge.DataSource.DataFields(n).Value
    where n is a string or integer variable.

    Have you confirmed that the referenced datafield (name or index number) exists (eg not a mis-typed name or a number out of range)?
    Do you get an error for every record with this datafield, or only for some records?
    Does it work correctly for all other datafields?

    If, on the other hand, you simply want to test whether a particular datafield has any data, you might use something like:

    If ActiveDocument.MailMerge.DataSource.DataFields(n).Value = vbNullString Then
      'No Data Exists
    Else
      'Data Exists
    End If


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Edited by macropodMVP Tuesday, November 15, 2011 9:47 AM Added code for testing data existence
    Tuesday, November 15, 2011 9:30 AM
  • ActiveDocument.MailMerge.DataSource.DataFields(n).Value
    where n is a string or integer variable.

    Presumably, you're actually using something like:

    Have you confirmed that the referenced datafield (name or index number) exists (eg not a mis-typed name or a number out of range)?
    Do you get an error for every record with this datafield, or only for some records?
    Does it work correctly for all other datafields?


    Hi

    I had the same problem while browsing throw data fields in debugger.

    But I finally solved the problem:

    Mail Merge data was produced by MS Dynamics CRM 4.0

    And some Merge Field names were too long. I threw out ONE last symbol from merge field names and its now OK.

    Tuesday, November 15, 2011 9:53 AM