Hi,
I am tring to create a Word VBA Mail Merge. I have a MySQL database that runs on a local machine and have a view setup called vwprintqueue. I am able to manually run the mail merge from inside Word but want the mail merge to complete automatically from a click of the button.
I have created the VBA code but can not get the merge to run as i get the errors:
"The operation can not be complete because of dialog or database engine failures. Please try again later"
&
"Word was unable to open the data source"
This happens when the code runs the line:
Call .OpenDataSource("C:\connection.dsn", , , , , , , , , , , sConnection, sSQL, , , wdMergeSubTypeWord2000)
and i have not got a clue why. The code i use is:
Do you know why I get those errors and how i can stop them?
Please see attached file.
Thanks in advance,
DW
I am tring to create a Word VBA Mail Merge. I have a MySQL database that runs on a local machine and have a view setup called vwprintqueue. I am able to manually run the mail merge from inside Word but want the mail merge to complete automatically from a click of the button.
I have created the VBA code but can not get the merge to run as i get the errors:
"The operation can not be complete because of dialog or database engine failures. Please try again later"
&
"Word was unable to open the data source"
This happens when the code runs the line:
Call .OpenDataSource("C:\connection.dsn", , , , , , , , , , , sConnection, sSQL, , , wdMergeSubTypeWord2000)
and i have not got a clue why. The code i use is:
Code:
Option Explicit
Sub AutoOpen()
Dim oForm As New frmReportMonth
'Open the form
With oForm
.Show
'If iReportMonth is greater than 1 run the report
If iReportMonth <> -1 Then
Call RunReport
End If
End With
End Sub
Private Sub RunReport()
Dim sConnection As String
Dim sSQL As String
sConnection = GetConnectionString
sSQL = GetSQL
'Run the mail merge
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
MsgBox ("STOP")
Call .OpenDataSource("C:\connection.dsn", , , , , , , , , , , sConnection, sSQL, , , wdMergeSubTypeWord2000)
Call .Execute
End With
Me.Close False, False, False
End Sub
Private Function GetRecords() As Recordset
Dim adoConn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim sSQL As String
Dim sConnStr As String
sConnStr = GetConnectionString()
Set adoRs = New ADODB.Recordset
Set adoConn = New ADODB.Connection
Call adoConn.Open(sConnStr)
sSQL = GetSQL
Call adoRs.Open(sSQL, adoConn)
Set GetRecords = adoRs
Set adoRs = Nothing
Set adoConn = Nothing
End Function
Private Function GetSQL() As String
GetSQL = "SELECT * from vwprintqueue;"
End Function
Do you know why I get those errors and how i can stop them?
Please see attached file.
Thanks in advance,
DW