I am developing a VB6 application that is accessing an Access 2003 database. From within the application I want to be able to open a
Mail Merge Document that receives data from a database view (CISWORD) in the Access database.
Here is a simplified example of what I am trying to do in the VB6 application:
Private Sub Command1_Click()
Dim sQuery As String
sQuery = "SELECT * FROM `CISWORD` WHERE ContractNo = 'XYZ' "
Dim oDoc As Word.Document
Set oDoc = Word.Documents.Add("C:\Contract Note.doc")
Call oDoc.MailMerge.OpenDataSource(gsMainDB, , , True, False, , , , , , , _
"Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\CIS.MDB;Mode=Read;", sQuery)
End Sub
The problem is that during execution of OpenDataSource a 'Confirm Data Source' window pops up in Word, with the following selection:
- OLE DB Database Files
- MS Access Databases via DDE
- MS Access Databases via ODBC
- Xtreme samples Databases via DDE
- CISTEST via ODBC
When I select OLE DB Database Files I am receiving a run-time error 5922: 'Word was unable to open the data source.'
When I select MS Access Databases via ODBC and afterwards the view CISWORD then the document shows the first record from the view
(which means it uses the query stored in the Mail Merge document, but not the one passed to the OpenDataSource method).
How can I prevent the 'Confirm Data Source' window from popping up and force Word to use the query passed to the OpenDataSource method?
If this is not possible with OLEDB I would also be fine with using an ODBC data source. I just don't want to use DDE.
Any help would be appreciated.
Thanks and kind regards,
Sebastian Daser
Infosystems Software & Service GmbH
sebastian.daser @ infosystems-gmbh.de
Mike - 15 Jul 2004 22:09 GMT
Sebastian,
Try changing:
sQuery = "SELECT * FROM `CISWORD` WHERE ContractNo = 'XYZ'"
to:
sQuery = "SELECT * FROM [CISWORD] WHERE (ContractNo = 'XYZ')"
Regards,
Mike
> I am developing a VB6 application that is accessing an Access 2003 database. From within the application I want to be able to open a
> Mail Merge Document that receives data from a database view (CISWORD) in the Access database.
[quoted text clipped - 32 lines]
> Infosystems Software & Service GmbH
> sebastian.daser @ infosystems-gmbh.de
Sebastian Daser - 16 Jul 2004 09:23 GMT
Hi Mike,
Unfortunately the effect is still the same.
Any other idea?
Thanks and kind regards,
Sebastian.
> Sebastian,
>
[quoted text clipped - 75 lines]
>>Infosystems Software & Service GmbH
>>sebastian.daser @ infosystems-gmbh.de
Mike - 16 Jul 2004 19:00 GMT
Try this: sQuery = "SELECT * FROM [CISWORD] WHERE ([ContractNo] = 'XYZ')"
Mike
> Hi Mike,
> Unfortunately the effect is still the same.
[quoted text clipped - 82 lines]
> >>Infosystems Software & Service GmbH
> >>sebastian.daser @ infosystems-gmbh.de
Sebastian Daser - 20 Jul 2004 10:47 GMT
Hi Mike,
Sorry to come back to you late, but I was stretched to length with other things and did not check news.
I have tried what you suggested, but the problem persists.
Thanks and best regards,
Sebastian.
> Try this: sQuery = "SELECT * FROM [CISWORD] WHERE ([ContractNo] = 'XYZ')"
>
[quoted text clipped - 96 lines]
>>>>Infosystems Software & Service GmbH
>>>>sebastian.daser @ infosystems-gmbh.de
Sebastian Daser - 20 Jul 2004 10:50 GMT
Hi Mike,
Sorry to come back to you late, but I was stretched to length with other things and did not check news.
I have tried what you suggested, but the problem persists.
Thanks and best regards,
Sebastian.
> Try this: sQuery = "SELECT * FROM [CISWORD] WHERE ([ContractNo] = 'XYZ')"
>
[quoted text clipped - 96 lines]
>>>>Infosystems Software & Service GmbH
>>>>sebastian.daser @ infosystems-gmbh.de