dougjack10
Technical User
I have a fairly simple request and I have been looking all over the internet for an answer.
All I want to do is;
Click on a button in access;
1. It opens a mail merge word document that has already been setup and linked to a query in the access database.
2. The document then merges to one letter, based on the current record in access form when I click the access button. The query in the mail merge document seems to be causing the problem.
3. The original mail merge document closes with no changes to the document.
4. The merged letter with the one record remains open.
I did have this working on a database years ago, using access 2003 and 2007. Although it does not seem to work in access 2010. See the code below. I ideally I am looking for some simple code that effectively has one variable, where I only need to put in the file path to the mail merge document.
If I remove the criteria in the access query, ([forms]![frm_name]![ID feild) that is linked to the merge document, it works and I get all 36 records merged letters into one document, but first of all I had to amend the registry,
This concerns me as I suspect this will need to be done to every machine that uses the database which seems impractical
My query includes criteria, [forms]![frm_name]![ID field] with the correct terms, and this seems to be causing the problem.
The error message is;
The method or property is not available because the document is not a mail merge.
Any ideas would be appreciated?
------------------------------------------------------------------------------------------------------------------------
Private Sub Command172_Click()
Dim stDocName As String
On Error GoTo Err_Command172_Click
Dim WordObj As Word.Application
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open ("F:\myfiles\letter.doc")
WordObj.Visible = True
With WordObj
.ActiveDocument.MailMerge.Execute
End With
With WordObj
Set WordDoc = .Documents.Open("F:\myfiles\letter.doc")
End With
With WordDoc
.Close SaveChanges:=False
End With
Exit_Command172_Click:
Exit Sub
Err_Command172_Click:
MsgBox Err.Description
End Sub
All I want to do is;
Click on a button in access;
1. It opens a mail merge word document that has already been setup and linked to a query in the access database.
2. The document then merges to one letter, based on the current record in access form when I click the access button. The query in the mail merge document seems to be causing the problem.
3. The original mail merge document closes with no changes to the document.
4. The merged letter with the one record remains open.
I did have this working on a database years ago, using access 2003 and 2007. Although it does not seem to work in access 2010. See the code below. I ideally I am looking for some simple code that effectively has one variable, where I only need to put in the file path to the mail merge document.
If I remove the criteria in the access query, ([forms]![frm_name]![ID feild) that is linked to the merge document, it works and I get all 36 records merged letters into one document, but first of all I had to amend the registry,
This concerns me as I suspect this will need to be done to every machine that uses the database which seems impractical
My query includes criteria, [forms]![frm_name]![ID field] with the correct terms, and this seems to be causing the problem.
The error message is;
The method or property is not available because the document is not a mail merge.
Any ideas would be appreciated?
------------------------------------------------------------------------------------------------------------------------
Private Sub Command172_Click()
Dim stDocName As String
On Error GoTo Err_Command172_Click
Dim WordObj As Word.Application
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open ("F:\myfiles\letter.doc")
WordObj.Visible = True
With WordObj
.ActiveDocument.MailMerge.Execute
End With
With WordObj
Set WordDoc = .Documents.Open("F:\myfiles\letter.doc")
End With
With WordDoc
.Close SaveChanges:=False
End With
Exit_Command172_Click:
Exit Sub
Err_Command172_Click:
MsgBox Err.Description
End Sub