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???
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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, 8 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
-
Uninstalr Updates
by
jv16
2 hours, 37 minutes ago -
Apple zero days for April
by
Susan Bradley
5 hours, 23 minutes ago -
CVE program gets last-minute funding from CISA – and maybe a new home
by
Nibbled To Death By Ducks
3 hours, 25 minutes ago -
Whistleblower describes DOGE IT dept rumpus at America’s labor watchdog
by
Nibbled To Death By Ducks
15 hours, 14 minutes ago -
Seeing BSOD’s on 24H2?
by
Susan Bradley
1 hour, 33 minutes ago -
TUT For Private Llama LLM, Local Installation and Isolated from the Internet.
by
bbearren
5 hours, 38 minutes ago -
Upgrade from Windows 10 to 11
by
Holdsworth8
23 hours, 54 minutes ago -
Microsoft : AI-powered deception: Emerging fraud threats and countermeasures
by
Alex5723
1 day, 2 hours ago -
0patch
by
WSjcgc50
3 hours, 43 minutes ago -
Devices might encounter blue screen exception with the recent Windows updates
by
Susan Bradley
20 hours, 6 minutes ago -
Windows 11 Insider Preview Build 22631.5261 (23H2) released to Release Preview
by
joep517
1 day, 5 hours ago -
Problem opening image attachments
by
RobertG
1 day, 7 hours ago -
advice for setting up a new windows computer
by
routtco1001
1 day, 22 hours ago -
It’s Identity Theft Day!
by
Susan Bradley
1 day, 2 hours ago -
Android 15 require minimum 32GB of storage
by
Alex5723
2 days, 2 hours ago -
Mac Mini 2018, iPhone 6s 2015 Are Now Vintage
by
Alex5723
2 days, 3 hours ago -
Hertz says hackers stole customer credit card and driver’s license data
by
Alex5723
2 days, 3 hours ago -
Firefox became sluggish
by
Rick Corbett
2 days ago -
Windows 10 Build 19045.5794 (22H2) to Release Preview Channel
by
joep517
2 days, 7 hours ago -
Windows 11 Insider Preview Build 22635.5235 (23H2) released to BETA
by
joep517
2 days, 8 hours ago -
A Funny Thing Happened on the Way to the Forum
by
bbearren
1 day, 5 hours ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
2 hours, 10 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
1 day, 5 hours ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
1 day, 7 hours ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
2 days, 22 hours ago -
The time has come for AI-generated art
by
Catherine Barrett
2 days, 2 hours ago -
Hackers are using two-factor authentication to infect you
by
B. Livingston
2 days, 12 hours ago -
23 and you
by
Max Stul Oppenheimer
2 days, 19 hours ago -
April’s deluge of patches
by
Susan Bradley
23 hours, 37 minutes ago -
Windows 11 Windows Updater question
by
Tex265
13 hours, 32 minutes 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.