I hope that although this is 25% Access and 75% Word, that someone will know
...
The whole problem here arises because 1) Microsoft acknowledges an 'issue'
wherein TextInput type FormFields are lost when doing a MailMerge and 2) the
fix that they have proposed is both inadequate and won't work from Access.
http://support.microsoft.com/?kbid=286841
The part of the code below that actually performs the merge is great; the
core of it is Albert D. Kalall's.
What I have tried to do is
1. put the Text FormFields into a collection
2. substitute "<ff>" for the formfield
2. merge the documents
3. substitute the formfield for "<ff>" from the collection
On 3, Access declares a data type mismatch.
Any help?
=================================
Const wdAllowOnlyFormFields = 2
Const wdNoProtection = -1
Const wdFieldFormTextInput = 70
Const wdFindContinue = 1
Public Function MergeQuery(queryName As String, _
docName As String) As Boolean
On Error GoTo handle_error
MergeQuery = False
Dim i As Integer
Dim mWord As Object
Dim mDoc As Object
Dim fField As Object
Dim ffObjects As Collection
Set ffObjects = New Collection
Set mWord = CreateObject("Word.Application")
DoCmd.TransferText acExportDelim, , queryName, "c:\merge.txt", True
With mWord
Set mDoc = .Documents.Open(docName)
.ActiveDocument.MailMerge.MainDocumentType = 0
If .ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
.ActiveDocument.Unprotect
End If
' Put each FormField into the ffObjects collection
For Each fField In .ActiveDocument.FormFields
If fField.Type = wdFieldFormTextInput Then
ffObjects.Add fField
fField.Select
.Application.Selection.TypeText "<ff>"
End If
Next fField
.ActiveDocument.MailMerge.OpenDataSource Name:="c:\merge.txt", _
AddToRecentFiles:=False,
Format:=0, _
Connection:="", SQLStatement:="",
SQLStatement1:=""
.ActiveDocument.MailMerge.Execute
' put form fields into new document
.Application.Selection.Find.ClearFormatting
i = 1
Do While .Application.Selection.Find.Execute(FindText:="<ff >", _
Wrap:=wdFindContinue, Forward:=True) = True
.ActiveDocument.FormFields.Add ffObjects(i)
i = i + 1
Loop
If .ActiveDocument.ProtectionType = wdNoProtection Then
.ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True,
Password:=""
End If
.Application.Visible = True
mDoc.Close
End With
MergeQuery = True
exit_point:
Set mWord = Nothing
Set mDoc = Nothing
Exit Function
handle_error:
LogError Err.Number, "MergeQuery", Err.Description
GoTo exit_point
End Function
===================================
Darryl Kerkeslager
Power corrupts.
Absolute power corrupts absolutely.
Knowledge is power.
See www.adcritic.com/interactive/view.php?id=5927