S
Sebastian Daser
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
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