Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 06-22-2024, 08:54 PM
Guessed's Avatar
Guessed Guessed is offline how to clear a text box in a form in word Windows 10 how to clear a text box in a form in word Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your code adds text alongside the bookmark, not inside the bookmark so it is hard to then clear that with other code. Rather than doing the extra steps to rectify that, I'm going to suggest what I consider a better alternative.

Your sample document doesn't include any code or userform information so it isn't immediately apparent what benefit you get out of using VBA so I'm going to suggest you perhaps consider getting rid of all the complexity of the userform and VBA and just go back to basics.
1. Set up your document with Content Controls instead of bookmark locations
2. Protect the document so the user can only edit the Content Controls
3. Save the document as a template so that you create new docs each time you want a 'cleared' form.

An alternative to #3 is to include a macro to clear the Content Controls (aka your original request before I drifted off on a tangent because bookmarks weren't as flexible as content controls and you haven't yet convinced me as to why a VBA userform was involved). Macros to clear all CCs or write to a specific one are below
Code:
Sub ClearCCs()
  Dim aCC As ContentControl
  For Each aCC In ActiveDocument.ContentControls
    aCC.Range.Text = ""
  Next aCC
End Sub

Sub WriteToCC()
  Dim aCC As ContentControl
  For Each aCC In ActiveDocument.SelectContentControlsByTitle("Rego")
    aCC.Range.Text = "This is the rego"
  Next aCC
End Sub
Attached Files
File Type: docm SHED SHEET TESTING JASON.docm (40.1 KB, 2 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 06-23-2024 at 04:16 PM.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to clear a text box in a form in word Reset "Button" to clear Word user-filled form, from all filled details. Rafi Word VBA 20 01-20-2023 02:16 PM
Clear all content controls (Text, dropdown) AND change option button values to FALSE in MS Word Form Janet D Word VBA 7 01-14-2023 02:36 AM
Clear Values from All Controls on Form ScottyBee Word VBA 2 04-02-2019 09:55 AM
how to clear a text box in a form in word Word Form to Save as and clear sfitzsimmons Word VBA 1 01-11-2019 02:03 PM
how to clear a text box in a form in word Don't clear form fields when protecting as a form BruceM Word 5 10-06-2016 08:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft