Consulting

Results 1 to 5 of 5

Thread: Access MailMerge DataSource in VBA

  1. #1
    VBAX Regular
    Joined
    Apr 2009
    Posts
    12
    Location

    Access MailMerge DataSource in VBA

    Hallo,

    I'm trying to acces the DataSource via
    Code:
    Doc.MailMerge.DataSource.DataFields(INDEX/FIELDNAME).Value
    usually this is no problem, but in case of two fields i get an error stating that the memory is corrupt/ or an Automation error!

    I have no problems accessing the Name property via: Code:
    Doc.MailMerge.DataSource.DataFields(INDEX/FIELDNAME).Name
    !

    Any ideas what wrong with those two fields?

    p.s.: when running the merge ALL fields are populated correctly! Only accessing the fields via VBA is causing an error!

    Here's the detailed error message:

    "Runtimeerror '-2147417848 (80010108)':

    Automation error
    The called object was disconnected from the clients"

    <- i translated it on my own as i recieve a german error!

    regards, advin

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    One possible cause of this is implicit instantiation caused by improperly qualified references used with early binding. Without seeing more of your code I can't suggest where this might be.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Regular
    Joined
    Apr 2009
    Posts
    12
    Location

    Additional information

    Hallo,

    it's actually quite simple to reproduce

    attached you can find a template and and xls- datasource.
    Please perform the following steps:
    1; Open template
    2; choose the mailmerge-datasource (ids_export_ready.xls)
    3; Open VB-editor -This document

    There you will find 3 simple code lines:
    [vba]Dim b As Variant
    b = ActiveDocument.MailMerge.DataSource.DataFields(3) 'change the index to 3 or 4 to see the error
    MsgBox (b)[/vba]

    the second line will fail for index 3 and 4 but work for the others.

    Please let me know if you need anything else or have an idea. Any help/hint is highly appreciated

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Please accept my apologies for the long delay in replying. I copied your files and they sat on my desktop unopened till now.

    The reason for your problem is the overlong names in your excel column headers:

    quoteid_promx_lineitemgroupid_promx_name
    quoteid_productid_promx_producttypeid_promx_name
    It should all work if you use shorter ones.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    VBAX Regular
    Joined
    Apr 2009
    Posts
    12
    Location
    Hallo,

    thanks for the info. I allready noticed that it works with shorter fieldnames. But I'm quite unsure why it fails?

    the problem is, that the datasource is delivered by another tool, so i have no possibilities to shorten the fieldnames in there.

    Are there any ways to modify the datasource in VB before accessing the fields?

    best regards, advin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •