locked
Event handler for document.MailMerge.OpenDataSource(...) to handle corrupt datasource using automation in c# RRS feed

  • Question

  • Hi,
    I was wondering if it is possible to handle the event where a corrupt(i.e., no tab, space , or any delimitation at all) datasource is opened . Right now a dialog pops up stating that the datasource is not valid and it blocks until I do something. Since, I'm using automation this must be caught inside the code. I have tried using .DisplayAlerts = WdAlertLevel.wdAlertsNone but this did stop the dialog from appearing. Is it possible to assign an eventhandler to the document object, so when the document.MailMerge.OpenDataSource(...)  is called I can prevent the dialog from popping by hanlding it in an eventhandler. However, I do not know what event handler to use. Thanks.

    BurgundySmudge

     
    Friday, February 13, 2009 8:21 PM

Answers

  • There is no event that fires when attaching a data source to a mail merge document. If this were VBA, you could name a procedure with the same name as the built-in command (if I recall correctly, that would be Sub OpenDataSource(), but it's been a while since I looked). Other than that, there's nothing.

    Word does not provide a way to suppress all message it could display. DisplayAlerts works for some things, but not everything.

    I suggest you test the data source before you use the OpenDataSource method. If you're interacting with the user, then provide the interface (dialog box) for the user to select the data source, then take care of linking it in yourself, after you've checked that it's valid.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by BurgundySmudge Wednesday, February 18, 2009 7:08 AM
    Monday, February 16, 2009 6:50 PM

All replies

  • There is no event that fires when attaching a data source to a mail merge document. If this were VBA, you could name a procedure with the same name as the built-in command (if I recall correctly, that would be Sub OpenDataSource(), but it's been a while since I looked). Other than that, there's nothing.

    Word does not provide a way to suppress all message it could display. DisplayAlerts works for some things, but not everything.

    I suggest you test the data source before you use the OpenDataSource method. If you're interacting with the user, then provide the interface (dialog box) for the user to select the data source, then take care of linking it in yourself, after you've checked that it's valid.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by BurgundySmudge Wednesday, February 18, 2009 7:08 AM
    Monday, February 16, 2009 6:50 PM
  • Hi,
    Thanks for the reply. I ended up writing a method which checked the size, delimitation, and the presence of headers to determine if the data source was viable. Thanks

    Burgundy Smudge
    Wednesday, February 18, 2009 7:07 AM