We have a form with text fields, and need to perform a mail merge with it. Of course, we have had to unprotect the form in order to perform the merge, which then works fine. However, once merged, the text fields have disappeared. Is there a solution to this? In other words to keep the text fields AND also perform a merge???
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
merging into a form with text fields (97/SR1)
Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » merging into a form with text fields (97/SR1)
- This topic has 6 replies, 4 voices, and was last updated 22 years, 10 months ago.
AuthorTopicWSpanderson
AskWoody LoungerJuly 24, 2002 at 8:52 pm #374059Viewing 2 reply threadsAuthorReplies-
WSsolomod
AskWoody LoungerJuly 25, 2002 at 5:08 am #603858You could try building the whole thing with a macro. We have a letter that uses a mailmerge from an Access database and writes the letter text as it goes. If you were to record a macro adding the fields you could add this in at the end of the merge.
I have attached our letter macro to this post. It’s very specialised but it does 2 merges and inserts mailmerge fields so you might be able to make use of bits of it. Very clumsy scripting I’m afraid but I’m still on the learning curve.
David
-
WSPhil Rabichow
AskWoody LoungerJuly 28, 2002 at 8:58 pm #604632I’m not sure I can help, as I’m a little unclear as to what you’re doing. When you say you need to perform a mail merge with your form, are you using the form as a main document or as a datasource? If the latter, could you be more specific as to how it’s laid out. Is there a table in it with variable data? Perhaps you could attach a sample to your post.
Cheers, -
WSpanderson
AskWoody Lounger -
WSPhil Rabichow
AskWoody LoungerJuly 29, 2002 at 3:49 pm #604781You can’t merge form fields. That is, when you perform the merge, the form fields themselves are not merged, so merely trying to reprotect the form without resettting form fields shouldn’t make a difference–there are no form fields left in the merged document. However, I copied the following tip from somewhere (I thought it was MS KB, but I’m not sure). Hope this helps.
MailMerge: Text Form Fields Are Not Retained
Word unlinks the text form fields during the mail merge. Word does not unlink display form fields, such as the drop-down and the check box form fields.You can work around the problem by using the following sample macros to:
1. Replace text form fields in the main mail merge document with placeholders while preserving the contents of the form fields.
2. Merge to a new document.
3. Replace the placeholders with text form fields and restore the contents of the form fields.
4. Restore the main mail merge document to its original content prior to running the macro.NOTE: These two macros work in conjunction with one another, and both macros must be created in the same Visual Basic for Applications project. The first macro will call the second macro.
Macro 1:
Sub PreserveMailMergeFormFields() Dim fFieldText() As String Dim iCount As Integer Dim fField As FormField Dim sWindowMain, sWindowMerge As String On Error GoTo ErrHandler ' Store Main merge document window name. sWindowMain = ActiveWindow.Caption ' Because the document contains form fields, ' it should be protected so, unprotect document. If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ' Loop through all text form fields ' in the main mail merge document. For Each aField In ActiveDocument.FormFields ' If the form field is a text form field... If aField.Type = wdFieldFormTextInput Then ' Redim array to hold contents of text field. ReDim Preserve fFieldText(1, iCount + 1) ' Place content and name of field into array. fFieldText(0, iCount) = aField.Result fFieldText(1, iCount) = aField.Name ' Select the form field. aField.Select ' Replace it with placeholder text. Selection.TypeText "" ' Increment icount iCount = iCount + 1 End If Next aField ' Perform mail merge to new document. ActiveDocument.MailMerge.Destination = wdSendToNewDocument ActiveDocument.MailMerge.Execute ' Find and Replace placeholders with form fields. doFindReplace iCount, fField, fFieldText() ' Protect the merged document. ActiveDocument.Protect Password:="", NoReset:=True, Type:= _ WdAllowOnlyFormFields ' Get name of final merged document. sWindowMerge = ActiveWindow.Caption ' Reactivate the main merge document. Windows(sWindowMain).Activate ' Find and replace placeholders with form fields. doFindReplace iCount, fField, fFieldText() ' Reprotect the main mail merge document. ActiveDocument.Protect Password:="", NoReset:=True, Type:= _ WdAllowOnlyFormFields ' Switch back to the merged document. Windows(sWindowMerge).Activate ErrHandler: End Sub
Macro 2:
Sub doFindReplace(iCount As Integer, fField As FormField, _ fFieldText() As String) ' Go to top of document. Selection.HomeKey Unit:=wdStory ' Initialize Find. Selection.Find.ClearFormatting With Selection.Find .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False ' Loop form fields count. For i = 0 To iCount ' Execute the find. Do While .Execute _ (FindText:="") = True ' Replace the placeholder with the form field. Set fField = Selection.FormFields.Add _ (Range:=Selection.Range, Type:=wdFieldFormTextInput) ' Restore form field contents and bookmark name. fField.Result = fFieldText(0, i) fField.Name = fFieldText(1, i) Loop ' Go to top of document for next find. Selection.HomeKey Unit:=wdStory Next End With End Sub
-
-
-
WScarbonnb
AskWoody LoungerJuly 29, 2002 at 11:47 am #604708If you want to keep the values in the FormFields after you unprotect the form, you will need to run a macro to reprotect the Form. It only needs to be 1 line:
ActiveDocument.Protect Type, NoReset, Password
There are 3 parameters to the Protect Method.
Type – is required and indicates the type of Protection (wdAllowOnlyFormFields to Protect for Forms)NoReset – is optional and indicates if the FormFields should be reset to default values or retain their current value (True = Retain Current Value False = Reset to default)
Password – is optional and is the protection password
So assuming that you do not have a password on you form, the actual line would look like:
ActiveDocument.Protect wdAllowOnlyFormFields,True
-
WSpanderson
AskWoody Lounger
-
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows Update orchestration platform to update all software
by
Alex5723
47 minutes ago -
May preview updates
by
Susan Bradley
2 hours, 26 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
2 hours, 33 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
28 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
12 hours, 56 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
15 hours, 35 minutes ago -
At last – installation of 24H2
by
Botswana12
16 hours, 19 minutes ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
5 hours, 57 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
1 day, 4 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
21 hours, 51 minutes ago -
Limited account permission error related to Windows Update
by
gtd12345
1 day, 17 hours ago -
Another test post
by
gtd12345
1 day, 18 hours ago -
Connect to someone else computer
by
wadeer
1 day, 12 hours ago -
Limit on User names?
by
CWBillow
1 day, 15 hours ago -
Choose the right apps for traveling
by
Peter Deegan
1 day, 5 hours ago -
BitLocker rears its head
by
Susan Bradley
13 hours, 32 minutes ago -
Who are you? (2025 edition)
by
Will Fastie
12 hours, 29 minutes ago -
AskWoody at the computer museum, round two
by
Will Fastie
1 day, 7 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
2 days, 4 hours ago -
Woody
by
Scott
2 days, 13 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
13 hours, 8 minutes ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
3 days, 4 hours ago -
MS Office 365 Home on MAC
by
MickIver
2 days, 21 hours ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
3 days, 18 hours ago -
Flash Drive Eject Error for Still In Use
by
J9438
12 hours, 53 minutes ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
4 days, 12 hours ago -
Windows 11 Insider Preview build 26120.4161 (24H2) released to BETA
by
joep517
4 days, 12 hours ago -
AI model turns to blackmail when engineers try to take it offline
by
Cybertooth
3 days, 16 hours ago -
Migrate off MS365 to Apple Products
by
dmt_3904
3 days, 17 hours ago -
Login screen icon
by
CWBillow
3 days, 7 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.