Hi
I'm upgrading one of my databases to 2010 (front end only).
In the 2003 version the code for running a mail merge works fine, but im getting a runtime 91 error - object variable or with block variable not set.
here is the code i'm using:
please can someone advise why this may not be working in 2010 - i've made sure the correct reference library is checked so its not that.
Thanks
Kev
edit - sorry it breaks at the line With oWord.MailMerge
I'm upgrading one of my databases to 2010 (front end only).
In the 2003 version the code for running a mail merge works fine, but im getting a runtime 91 error - object variable or with block variable not set.
here is the code i'm using:
Code:
Dim mypath As String
Dim mypath3 As String
Dim Wordpath As String
Dim sDBPath As String
Dim oApp As Word.Application
Dim ThisDB As String
Dim oWord As Word.Document
Dim oMainDoc As Word.Document
Wordpath = Environ("office") & "\winword.exe"
mypath = Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name)))
mypath3 = ("" & mypath & "merge test.doc""")
ThisDB = CurrentDb.Name
Set oApp = CreateObject("Word.Application")
Set oWord = oApp.Documents.Open(FileName:=mypath3)
oApp.Visible = True
With oWord.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = ThisDB
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM [tblWriteToClient]"
End With
With oWord
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
oWord.Close
DoCmd.SetWarnings True
please can someone advise why this may not be working in 2010 - i've made sure the correct reference library is checked so its not that.
Thanks
Kev
edit - sorry it breaks at the line With oWord.MailMerge