none
Error 5922 doing a mail merge with Word 2010

    Question

  • I am using Visual Basic 9.0 (Visual Studio 2008).  My application does a mail merge using Microsoft Word (connected to a Microsoft Access database).  It works fine with previous version of Microsoft Word.  However, it does not work with Microsoft Word 2010 for some reason.  The merge fails on the call to .OpenDatasource which generates an error 5922 (Word was unable to open the data source).

    The line that fails reads:

    wordDoc.MailMerge.OpenDataSource(

    "", , 0, 1, 1, 0, "", "", 0, "", "", odbcConnectString, sqlSelectStmt, "", , WDMergeSubTypeWord2000)

    the value of odbcConnectString is:

    DSN=Market Drive Staging;DBQ=C:\Users\Andy\AppData\Local\Temp\tmpC30F.tmp;DefaultDir=C:\Users\Andy\AppData\Local\Temp\;DriverID=25;FIL=MS Access;MaxBufferSize=4096;PageTimeout=5;UID=Admin;PWD=

    the value of sqlSelectStmt is:

    SELECT * FROM `RELettersMailMerge` ORDER BY `Order`

    To repeat, this works just fine with Word 2007 and Word 2003.  Any ideas would be greatly appreciated.

     


    andy
    • Moved by Martin_Xie Monday, October 18, 2010 11:32 AM Move it to Word Development Forum for better support. (From:Visual Basic General)
    Saturday, October 16, 2010 2:11 AM

Answers

  • HI Cindy.

    I used the macro trick to get a connection string that would work and then I changed one thing at time to figure out why my original code did not work.  Here is what I found.

    1. Office 2010 requires that the 'DatabaseName' parameter is filled in.  This was not expected because teh connection string has all the information needed to connect to the database and prior version of office did not require this. 

    2. The database extension of the mail merge data file must be .mdb!  In my original example, I was using a temporary filename which had a .tmp extension.  It had a .tmp extension because the facility in the .net framework that generates and returns a temporary filename puts it there.  The actual filename of the Access database and its extension should not matter.  The connection string already tells you what driver should be used to read the file.

    Can you tell me why these are not both bugs (especially the second one)?

    To work around the problem, the facility that returns a temporary filename will need to be 'wrapped' to return a filename with a particular extension.  That wrapper will have to check to see if the temporary filename with the new extension already exists in the temporary folder and then try generating another temp filename if it does.  This is because the .net function that returns temporary filenames will not be checking for an existing file with a different extension to ensure uniqueness.

    Andy

     


    andy
    • Marked as answer by andy pelkey Friday, October 29, 2010 6:15 PM
    Friday, October 29, 2010 6:14 PM

All replies

  • You may post this in word developers forum maybe some will shed light on it for you http://social.msdn.microsoft.com/Forums/en-US/worddev/threads

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    Saturday, October 16, 2010 5:07 AM
  • Hello Andy,

    Thanks for contacting Word for developers forum. I also guess it may be related to be SubType parameter. Have you tried to use a difference value on SubType parameter, such as wdMergeSubTypeWord and others. For more information, please see this KB article: http://support.microsoft.com/kb/827891. The above suggestion is just my thought. If it does not help you, would you please tell us more information on this issue?

    Would you mind sharing the source code about this issue? So that I could use it in my side to reproduce this issue. Then I could do some further research on it. Thanks! Have a nice day.

    Best regards,
    Bessie Zhao - MSFT
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, October 19, 2010 3:45 AM
  • Hi Andy

    I recommend you record a VBA macro while creating a manual link (as an end-user) to this data source. That will tell you about the syntax Word wants to have - and Word is very finicky about data source connections.

    In order to force an ODBC connection, you need to click the "Show All" checkbox in the Confirm Data Source dialog box, then choose the appropriate ODBC driver from the list. Question is, however, if you really want to continue using ODBC, or whether you should switch to OLE DB (the default since Word 2003). Mind you, there could be reasons for not switching, but only if you're sure you want to retain ODBC for such a  reason...

    Also, in what file format is the Access database?


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Monday, October 25, 2010 9:26 AM
    • Unmarked as answer by andy pelkey Friday, October 29, 2010 6:14 PM
    Tuesday, October 19, 2010 7:32 AM
    Moderator
  • Hello again Andy,

    I am writing to check the status of the issue on your side. If you have any questions or concerns, please feel free to let us know. We will be more than happy to be of assistance.

    Best regards,
    Bessie Zhao - MSFT
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, October 22, 2010 9:22 AM
  • Hi Cindy.

    Thank you for the reply.  I did not get a notification of your answer which is why i didn't reply earlier.  Sometimes I forget to check the box when creating a post to send an email when there is activity.

    I will try what you suggest.  The Access database is in the Access 2003 format. 


    andy
    Friday, October 29, 2010 5:10 PM
  • Hi Cindy.

    Do you know where I can find documentation on how to connect Word to the Access database using OLEDB rather than ODBC?

    Andy


    andy
    Friday, October 29, 2010 5:12 PM
  • HI Cindy.

    I used the macro trick to get a connection string that would work and then I changed one thing at time to figure out why my original code did not work.  Here is what I found.

    1. Office 2010 requires that the 'DatabaseName' parameter is filled in.  This was not expected because teh connection string has all the information needed to connect to the database and prior version of office did not require this. 

    2. The database extension of the mail merge data file must be .mdb!  In my original example, I was using a temporary filename which had a .tmp extension.  It had a .tmp extension because the facility in the .net framework that generates and returns a temporary filename puts it there.  The actual filename of the Access database and its extension should not matter.  The connection string already tells you what driver should be used to read the file.

    Can you tell me why these are not both bugs (especially the second one)?

    To work around the problem, the facility that returns a temporary filename will need to be 'wrapped' to return a filename with a particular extension.  That wrapper will have to check to see if the temporary filename with the new extension already exists in the temporary folder and then try generating another temp filename if it does.  This is because the .net function that returns temporary filenames will not be checking for an existing file with a different extension to ensure uniqueness.

    Andy

     


    andy
    • Marked as answer by andy pelkey Friday, October 29, 2010 6:15 PM
    Friday, October 29, 2010 6:14 PM