Hi,
After being forced to use Office 2010 (I was using Office 2003) I'm encountering problems with my database. The function below was working fine in Access 2003. However, now I'm forced to switch to Office 2010, and the function isn't working anymore. Can anybody help me?
Best regards,
Mathijs
After being forced to use Office 2010 (I was using Office 2003) I'm encountering problems with my database. The function below was working fine in Access 2003. However, now I'm forced to switch to Office 2010, and the function isn't working anymore. Can anybody help me?
Best regards,
Mathijs
Code:
Public Function MergeQuest(strFileName As String, strQueryName As String, strDBpath As String)
On Error GoTo ErrHandling
Dim objDoc As Word.Document
Dim objWord As Word.Application
Dim blnCreated As Boolean
On Error Resume Next
Set objWord = GetObject("Word.Application")
If Err Then
Set objWord = CreateObject("Word.Application")
blnCreated = True
End If
On Error GoTo ErrHandling
Set objDoc = objWord.Documents.Open("" & strFileName & "")
'Make Word Visible
objWord.Visible = True
'Execute the MailMerge
With objDoc.mailmerge
'Set Merge Data Source
objDoc.mailmerge.OpenDataSource Name:=strDBpath, _
LinktoSource:=True, _
Connection:="QUERY " & strQueryName, _
SQLStatement:="SELECT * FROM " & strQueryName
.Destination = wdSendToNewDocument
.Execute
'objWord.ActiveDocument.PrintOut False
'objWord.ActiveDocument.Close wdDoNotSaveChanges
' print the document
objWord.ActiveDocument.PrintOut
Do While objWord.BackgroundPrintingStatus > 0
Loop
End With
'probleem oplossen: automate multiple instances of Microsoft Word simultaneously
objWord.NormalTemplate.Saved = True
'Close The form files and the merged document
objDoc.Close wdDoNotSaveChanges
If blnCreated Then
objWord.Quit
End If
Set objDoc = Nothing
Set objWord = Nothing
Exit Function
ErrHandling:
MsgBox "Whoops" 'Better error handling of course
End Function