Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2021, 10:54 AM
shaun0406 shaun0406 is offline Clear Button For Specific Content Control Windows 10 Clear Button For Specific Content Control Office 2010
Novice
Clear Button For Specific Content Control
 
Join Date: Dec 2020
Posts: 19
shaun0406 is on a distinguished road
Default Clear Button For Specific Content Control

Hello,

How can I make a button to clear some content control, but not everything.
I am creating a form that can be reuse next year with some information changes every year while some initial input stays the same.

Example, I have Content Control Tag/Title Name, DOB, Product, Price


If I press the "clear button" Product and Price would clear, but Name and DOB will not be clear and stay as is it written

Thank You
Reply With Quote
  #2  
Old 06-07-2021, 03:53 PM
Guessed's Avatar
Guessed Guessed is offline Clear Button For Specific Content Control Windows 10 Clear Button For Specific Content Control Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

I would use a consistent Tag value in each CC that needs to be wiped by the macro. For example, set the Tag property to "Annual" for the plain text CCs you want to wipe.

The macro that then wipes those ones (at its simplest) would be
Code:
Sub DeciduousCCs()
  Dim aCC As ContentControl
  For Each aCC In ActiveDocument.SelectContentControlsByTag("Annual")
    aCC.Range.Text = ""
  Next aCC
End Sub
You might need to complicate this if it doesn't work with the CC types in your document.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 06-09-2021, 02:15 PM
shaun0406 shaun0406 is offline Clear Button For Specific Content Control Windows 10 Clear Button For Specific Content Control Office 2010
Novice
Clear Button For Specific Content Control
 
Join Date: Dec 2020
Posts: 19
shaun0406 is on a distinguished road
Default

I tried using the code given, but I couldn't figure out how to use it.

But I have of thought of something but I do not know how to code it.
Say I have Content Control Title: Price and Product, both Tags "Annual" (assuming these values changes every year and other tags don't)

Maybe by using a event on exit

I add a rich text cc TAG: Clear
If I Select the field with the Clear Tag (On entry) then exit the field (On Exit)
Tags with "Annual" would clear
Reply With Quote
  #4  
Old 06-09-2021, 03:29 PM
Guessed's Avatar
Guessed Guessed is offline Clear Button For Specific Content Control Windows 10 Clear Button For Specific Content Control Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Post an example document with some tagged CCs and I will test the macro on that to see where you are going wrong.

I wouldn't recommend the on exit macro. That seems too easy to trigger and likely to cause data loss when you don't intend it.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 06-12-2021, 08:37 AM
shaun0406 shaun0406 is offline Clear Button For Specific Content Control Windows 10 Clear Button For Specific Content Control Office 2010
Novice
Clear Button For Specific Content Control
 
Join Date: Dec 2020
Posts: 19
shaun0406 is on a distinguished road
Default

Here is my sample document.

Fields with tag annual in that document are just few of many. So ideally I want the fields with the annual tag to be cleared out once for it not to be confusing to the user with the new values(this year) and old values(last year), instead of having the fields be cleared only when clicked/selected
Attached Files
File Type: docm Sample Doc.docm (50.2 KB, 8 views)
Reply With Quote
  #6  
Old 06-14-2021, 02:04 AM
Guessed's Avatar
Guessed Guessed is offline Clear Button For Specific Content Control Windows 10 Clear Button For Specific Content Control Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

The easiest way to use the macro is to add a MacroButton Field below the table. You then run the macro by double clicking that text. To do this:
1. Stop the Protection
2. Put your cursor immediately below the table and paste the following line of text
MacroButton DeciduousCCs Double Click to clear Annual fields
3. Select that text, change its colour so it stands out (eg Red) and press Ctrl+F9, then press F9 to hide the field code.
4. Reprotect the document
5. Make sure the macro is sitting in a module in the document and that macros are enabled.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 06-14-2021, 10:55 AM
shaun0406 shaun0406 is offline Clear Button For Specific Content Control Windows 10 Clear Button For Specific Content Control Office 2010
Novice
Clear Button For Specific Content Control
 
Join Date: Dec 2020
Posts: 19
shaun0406 is on a distinguished road
Default

I modified the line
Code:
aCC.Range.Text = ""
to
Code:
aCC.Range.Delete
With the range.text, I couldn't clear the annual fields in a protected documents. But with Range.Delete I was able to clear the annual fields with no problem

But this works perfectly, Thank You!
Reply With Quote
Reply

Tags
clearcontents, content control, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to get a word document to send specific content via email using submit button ActualJax Word VBA 2 07-06-2020 04:18 PM
Clear Button For Specific Content Control Finding specific Content Control based on both title and tag ZaSpai Word VBA 4 03-31-2019 11:37 AM
Adding Row with Content control using Command Button baes10 Word VBA 0 12-13-2017 11:30 AM
Content Control Option Button Oops warbird Word VBA 5 12-07-2017 06:53 AM
Clear Button For Specific Content Control Code to Sum Column of Content Control Values In Specific Tables? warbird Word VBA 2 07-13-2015 05:44 AM

Other Forums: Access Forums

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


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