| re: Opening a mail merge document from Access 2000
Hi again
[color=blue]
> If I just open the document (i.e. a letter displaying address and contact
> details) in Word (after running my append query in Access) the document
> opens with the data displayed in the appropriate merged fields from the
> table of source data in Access. I also get a message when i open the
> document in Word saying:
> "Opening this document will run the following SQL command: SELECT *[/color]
FROM[color=blue]
> 'Filename'. Do you want to continue?"
>
> I then proceed with the "Yes" prompt to display my data in the document.
> This document can then be merged to a new document for the user to save as[/color]
a[color=blue]
> new file and print off if required. When I run my code in Access to open[/color]
the[color=blue]
> letter I do not recieve the message that I mentioned above, which makes me
> wonder if I have missed out some code to tell Access to perform the mail
> merge.[/color]
Oh I've had all sorts of 'fun' with Word 2003 finding old merge header info
in (supposedly) long since cleared out documents that no longer use standard
mail merge - but were still prompted by an annoying confirmation message.
[color=blue]
>
> Basically my users want to be able to have an automated process of opening
> various letters in Word from Access, with the data being sourced from the
> database.[/color]
Yes - that's totally fair enough. But you'll need to have a clear imagine
in your mind of the end point you want to reach.
What state do you want the documents to be in at the end of it all?
If you look in the cut down function I've pasted below - there are three
different ways you could go with it at the end.
See which is right for you.
Setting the source during the merge might also provide us with some more
information of where things might be going awray.
Just enter your file path and table name as appropriate.
Function TestMerge()
Dim objWord As Object
Dim objDoc As Object
Dim strFullPath As String
'Do your data update
fMergeDataUpdate 'or whatever it's called
'Making sure it's up to date for a second can't hurt
DoEvents
Const cstrMergeTable = "" 'Your merge table name
strFullPath = "" 'Your document file
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo errHere
Set objDoc = objWord.Documents.Open(strFullPath)
With objDoc.MailMerge
fWriteOut "Assigning merge source"
.OpenDataSource Name:=CurrentDb.Name, LinkToSource:=True,
AddToRecentFiles:=False, _
Format:=wdOpenFormatAuto, Connection:="TABLE " &
cstrMergeTable, _
SQLStatement:="SELECT * FROM " & cstrMergeTable
'If you want data displayed instead of the merge fields
'.ViewMailMergeFieldCodes = False
'If you want to see the merge fields
'.ViewMailMergeFieldCodes = True
'if you want it merged into a new document - no merge fields at all
.Execute
End With
objWord.Visible = True
exitHere:
Set objDoc = Nothing
Set objWord = Nothing
Exit Function
errHere:
MsgBox Err.Description, vbExclamation
Resume exitHere
End Function |