Computer Learning Zone CLZ Access Excel Word Windows

There is no shame in not knowing. The problem arises when irrational thought and attendant behavior fill the vacuum left by ignorance.

-Neil deGrasse Tyson
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Microsoft Word Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Protecting Form Fields
Daniel Golden 
     
16 months ago
I have several form fields in a document in which I have created a UserForm to gather information to populate the various fields using bookmarks. I have the document protected but allow for edits in the various fields by the users. My issue is that if a user deletes all information in a form field it deletes the bookmark from the document. Is there a way to protect the bookmark so that if the information in the form field is deleted it doesn't delete the bookmark?
Richard Rost  @Reply  
          
16 months ago
Didn't know the answer to this off the top of my head, but here's what GPT has to say about it:

Yes, when a user deletes all the text in a form field, Word removes the associated bookmark. To prevent this while allowing users to edit the fields, you can use VBA to restore the bookmark if it is deleted. Here are a few approaches:

**Solution 1: Use VBA to Restore the Bookmark**
You can create a macro that runs when the document is opened or before printing to check for missing bookmarks and restore them if needed.

**Steps:**
1. Open the VBA Editor (`Alt + F11`).
2. Insert a new module.
3. Add the following code:

CodeSub RestoreBookmarks()
    Dim bm As Bookmark
    Dim rng As Range
    Dim bmName As String

    ' List of bookmarks to check
    Dim bmList As Variant
    bmList = Array("Bookmark1", "Bookmark2", "Bookmark3") ' Update with your bookmark names

    For Each bmName In bmList
        If ActiveDocument.Bookmarks.Exists(bmName) = False Then
            ' Restore the bookmark at its original position
            Set rng = ActiveDocument.Range
            rng.Collapse wdCollapseEnd
            rng.Text = "[Placeholder]" ' Insert placeholder text
            ActiveDocument.Bookmarks.Add bmName, rng
        End If
    Next bmName
End Sub


4. Run this macro manually or set it to trigger on `Document_Open` or `Document_BeforeSave`.

---

**Solution 2: Use a Macro-Enabled Form Field**
If you're using form fields (`Legacy Form Fields`), you can modify them to prevent the deletion of bookmarks.

**Steps:**
1. Double-click on the form field to open Form Field Options.
2. Check Calculate on exit.
3. Add the following VBA code in the VBA Editor (`Alt + F11`):

CodePrivate Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Dim bmName As String
    bmName = ContentControl.Title ' Ensure the Content Control has a Title matching the bookmark name
    
    ' Restore bookmark if deleted
    If ActiveDocument.Bookmarks.Exists(bmName) = False Then
        ActiveDocument.Bookmarks.Add bmName, ContentControl.Range
    End If
End Sub


This ensures the bookmark is automatically recreated when the user exits the field.

---

**Solution 3: Use a Content Control Instead of a Form Field**
If possible, use Content Controls instead of Form Fields, as they retain bookmarks even when cleared.

**Steps:**
1. Unlock the document and replace the form fields with Rich Text Content Controls.
2. Set each control's Tag or Title to match the bookmark name.
3. Protect the document again.

Since Content Controls don't remove bookmarks when cleared, this method is the simplest if it suits your workflow.

---

**Summary**
- Use VBA to check and restore missing bookmarks (`RestoreBookmarks` macro).
- Enable "Calculate on Exit" in form fields to force re-evaluation.
- Use Content Controls instead of form fields to avoid deletion issues.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Microsoft Word Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/12/2026 5:38:47 PM. PLT: 0s