If the formfields in the main document are only of the TextInput type and
there are no On Entry/On Exit macros associated with any of the formfields,
then you, can use the following macro to execute the merge to a new document
in which the formfields will be reinstated (albeit without their bookmark
names, which is of probably no consequence in this situation)
Sub MergewithFormFields()
Dim i As Long
With ActiveDocument
For i = .FormFields.Count To 1 Step -1
If .FormFields(i).Type = wdFieldFormTextInput Then
.FormFields(i).Range.Text = "FF" & i
End If
Next i
With .MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
End With
Selection.HomeKey wdStory
With Selection.Find
Do While .Execute(FindText:="FF[0-9]{1,}", Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=True) = True
ActiveDocument.FormFields.Add Selection.Range, wdFieldFormTextInput
Loop
End With
End Sub
You will however then end up with a single document which you would then
need to split into the individual documents that you want to send out to
your field offices.
For that, see the "Individual Merge Letters" item on fellow MVP Graham Mayor's
website at:
http://www.gmayor.com/individual_merge_letters.htm
Alternatively, if you run the following macro when the mail merge main
document is the active document, it will convert each MERGEFIELD in the
document to a DOCVARIABLE field and then it will create a new document for
each record in the datasource in each of which the values of the document
variables will be set to the corresponding data from the data source:
Sub MergewithFormFields()
Dim dSource As String
Dim qryStr As String
Dim mfCode As Range
Dim i As Long, j As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
With ActiveDocument
'Get the details of the datasource
With .MailMerge.DataSource
dSource = .Name
qryStr = .QueryString
End With
'Convert the MERGEFIELDS to DOCVARIABLE fields
For i = 1 To .Fields.Count
If .Fields(i).Type = wdFieldMergeField Then
Set mfCode = .Fields(i).code
mfCode = Replace(mfCode, "MERGEFIELD", "DOCVARIABLE")
End If
Next i
'Convert the Mail Merge Main document to a normal Word document
.MailMerge.MainDocumentType = wdNotAMergeDocument
End With
' Open the database
Set db = OpenDatabase(dSource)
' Retrieve the recordset
Set rs = db.OpenRecordset(qryStr)
With rs
' Move to the first record
.MoveFirst
j = 1
Do While Not .EOF
'Create variables in the document with the names and values
'of the fields in each record
For i = 0 To .Fields.Count - 1
If .Fields(i).Value <> "" Then
ActiveDocument.Variables(.Fields(i).Name).Value =
..Fields(i).Value
End If
Next i
ActiveDocument.Fields.Update
ActiveDocument.SaveAs "C:\Test\MwithFF" & j
.MoveNext
j = j + 1
Loop
End With
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
With the above code as written, each documnet is saved in a folder C:\Test\
with a file name of the form MwithFF# where # is from 1 to the number of
records in the data source. It is a fairly simple matter to modify the code
so that each document is saved with a name that is taken from a field in the
data source and making use of the information in the following article, if
the email addresses were also present in one of the fields in the
datasource, the code could be further modified to email each document to the
respective email addresses.
See the article "How to send an email from Word using VBA" at:
http://www.word.mvps.org/FAQs/InterDev/SendMail.htm
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
AJ said:
The second case, we will be doing the merge at the office and then email
documents all over the state, then field officers will fill in data and
return to us then we will import into database. We do not have an open
database to our field officers. They need some info (what we merge) to go
out
to do inspections then they are going to be sending back their findings
and
we will update database.