noboffinme
Registered User.
- Local time
- Tomorrow, 04:00
- Joined
- Nov 28, 2007
- Messages
- 288
Hi
I have the below code taken from the examples db on this forum to perform a Mail Merge with a saved Word doc.
It's throwing an error as it tries to find the Word doc for the 'oMainDoc' variable.
I've checked the ref libraries & used a 2003, a 2007 docx & also a 2007 standard Word doc but the code cannot locate the Word file - path is correct though.
I'd like to use a 2007 version Word doc since the db is built in Access 2007 so what could be causing this problem??
'---------------------------
Private Sub cmd_mm_ctcts_Click()
Dim oMainDoc As Word.Document
Dim oSel As Word.Selection
Dim sDBPath As String
Set oMainDoc = oApp.Documents.Open("C:\Documents and Settings\Database\letter")
oApp.Visible = True
With oMainDoc.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = "C:\Documents and Settings\Database.mdb"
.OpenDataSource Name:=sDBPath, SQLStatement:="SELECT * FROM [qry_mm_ctcts]"
End With
With oMainDoc
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
End Sub
'--------------------------------------------------
I have the below code taken from the examples db on this forum to perform a Mail Merge with a saved Word doc.
It's throwing an error as it tries to find the Word doc for the 'oMainDoc' variable.
I've checked the ref libraries & used a 2003, a 2007 docx & also a 2007 standard Word doc but the code cannot locate the Word file - path is correct though.
I'd like to use a 2007 version Word doc since the db is built in Access 2007 so what could be causing this problem??
'---------------------------
Private Sub cmd_mm_ctcts_Click()
Dim oMainDoc As Word.Document
Dim oSel As Word.Selection
Dim sDBPath As String
Set oMainDoc = oApp.Documents.Open("C:\Documents and Settings\Database\letter")
oApp.Visible = True
With oMainDoc.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = "C:\Documents and Settings\Database.mdb"
.OpenDataSource Name:=sDBPath, SQLStatement:="SELECT * FROM [qry_mm_ctcts]"
End With
With oMainDoc
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = 1
oApp.ActiveWindow.WindowState = 1
End Sub
'--------------------------------------------------