Answered by:

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).

Answers

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.

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.

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...

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.

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.