Click to See Complete Forum and Search --> : Mailmerging from Access to Word


Stevie G
March 14th, 2005, 04:14 PM
Can anyone help me with the following code?
If I reboot my machine, open the Db and run the wordmerge, A WORD msg pop up with "Do you want to save the changes to letters1?" with a Y/N, cancel option. If I chose yes and then cancel, the word document will open and the code runs ok but, I am not sure that this is good practice as it leads to confussion. I am also trying to eliminate the msg that explains to user that they are about to merge from access to word. I think it will just confuse the user even more. However, If there is no work around, then I will have to live with that. Very greatful for any assistance, Cheers, Steve


Private Sub cboReport_Change()
On Error GoTo Err_Handler
If Nz(Len(Me.cboReport), 0) = 0 Then
MsgBox "You must select a correspondance letter"
Else
Dim WordObj As Word.Document
Dim strPathtoYourDocument
strPathtoYourDocument = "D:\Data\Frm_" & Me.cboReport & ".doc"
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryMailMerge"
DoCmd.SetWarnings True
Set WordObj = GetObject(strPathtoYourDocument)
WordObj.MailMerge.Destination = wdSendToNewDocument
WordObj.MailMerge.Execute
WordObj.Close wdDoNotSaveChanges
WordObj.Application.Quit
Set WordObj = Nothing
Exit Sub
Err_Handler:
Beep
MsgBox "You have cancelled this operation."

Exit Sub
End If
End Sub