Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2021, 01:43 PM
Tobee11 Tobee11 is offline Creating drop down list content control with "if" conditions Windows XP Creating drop down list content control with "if" conditions Office 2019
Novice
Creating drop down list content control with "if" conditions
 
Join Date: Aug 2021
Posts: 5
Tobee11 is on a distinguished road
Default Creating drop down list content control with "if" conditions

Hello, I need to create a drop down list content control box with a simple condition.



My drop down contains 2 options

If the first option is chosen, I need an additional plain text content control box to appear beneath

If the second option is chosen, nothing would happen

How do I achieve this? Thank you.
Reply With Quote
  #2  
Old 08-11-2021, 03:42 PM
Guessed's Avatar
Guessed Guessed is offline Creating drop down list content control with "if" conditions Windows 10 Creating drop down list content control with "if" conditions 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

What are you like with macros? If you do a search in this forum for ContentControlOnExit you will find lots of examples of code that runs automatically when you change a CC. Then it is a case of showing/hiding the paragraph/row where the other CC sits.

If you don't know how to adapt that code, you should post a sample document showing what you have.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-11-2021, 05:03 PM
Tobee11 Tobee11 is offline Creating drop down list content control with "if" conditions Windows XP Creating drop down list content control with "if" conditions Office 2019
Novice
Creating drop down list content control with "if" conditions
 
Join Date: Aug 2021
Posts: 5
Tobee11 is on a distinguished road
Default Creating drop down list content control with "if" conditions

Macros will be a stretch for me, but I'll look at the ContentControlOnExit posts and do my best.

I've attached a simple example of my sheet here.

If user selects "yes" in initial control box, I want the text box to open.

If user selects "no", then nothing happens.

I need this to carry over to an Outlook message. I'm using content controls in outgoing messaging using Quick Parts. Will the macros copy over to Outlook?

I appreciate any help. Thanks!
Attached Files
File Type: docx Test.docx (18.7 KB, 14 views)
Reply With Quote
  #4  
Old 08-11-2021, 05:23 PM
Guessed's Avatar
Guessed Guessed is offline Creating drop down list content control with "if" conditions Windows 10 Creating drop down list content control with "if" conditions 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

OK, do a SaveAs on that file and change the type to docm

Set the Title Property of the first CC to 'Interested"
Set the Title Property of the second CC to "Explain"

Add the following macro to the ThisDocument module in the file
Code:
Private Sub Document_ContentControlOnExit(ByVal thisCC As ContentControl, Cancel As Boolean)
  Dim aCC As ContentControl, bHide As Boolean
  
  If thisCC.Title = "Interested" Then
    bHide = thisCC.Range.Text = "No"
    'bHide = Not thisCC.Range.Text = "Yes"   'this alternative treats a non-selection differently
  End If
  
  'Change the hidden property on the dependent CC paragraph
  For Each aCC In ActiveDocument.SelectContentControlsByTitle("Explain")
    aCC.Range.Paragraphs(1).Range.Font.Hidden = bHide
  Next aCC
  
  'Ensure hidden text is not visible on screen
  With ActiveWindow.View
    .ShowHiddenText = False
    .ShowAll = False
  End With
End Sub
Then change the value in the dropdown and move the cursor out of the CC.

Note that I put two alternatives for bHide in the code. You can enable or disable these lines by adding/removing the ' from the start. The difference is how it treats the top option ie blank.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 08-11-2021, 08:48 PM
Tobee11 Tobee11 is offline Creating drop down list content control with "if" conditions Windows XP Creating drop down list content control with "if" conditions Office 2019
Novice
Creating drop down list content control with "if" conditions
 
Join Date: Aug 2021
Posts: 5
Tobee11 is on a distinguished road
Default

I thought I had it working, but running into issues.

My document attached.

I insert the Macro and run, but it isn't working as intended.

Appreciate any help to indicate what I'm doing wrong.

Much appreciated.
Reply With Quote
  #6  
Old 08-11-2021, 08:56 PM
Tobee11 Tobee11 is offline Creating drop down list content control with "if" conditions Windows XP Creating drop down list content control with "if" conditions Office 2019
Novice
Creating drop down list content control with "if" conditions
 
Join Date: Aug 2021
Posts: 5
Tobee11 is on a distinguished road
Default

Here is the file
Attached Files
File Type: docm Doc8.docm (22.6 KB, 27 views)
Reply With Quote
  #7  
Old 08-11-2021, 09:11 PM
Guessed's Avatar
Guessed Guessed is offline Creating drop down list content control with "if" conditions Windows 10 Creating drop down list content control with "if" conditions 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

You put the code in the wrong module. Take it out of Module1 and put it into ThisDocument.

The module is 'special' as having the code there allows it to be fired off by document events rather than needing you to tell Word when to run it.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 08-12-2021, 02:38 PM
Tobee11 Tobee11 is offline Creating drop down list content control with "if" conditions Windows XP Creating drop down list content control with "if" conditions Office 2019
Novice
Creating drop down list content control with "if" conditions
 
Join Date: Aug 2021
Posts: 5
Tobee11 is on a distinguished road
Default

Perfect. Many thanks for walking me through it!
Reply With Quote
Reply

Tags
conditions, content control

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating drop down list content control with "if" conditions Assigning Macro to Drop Down list Content Control aussiew Word VBA 5 03-10-2019 02:55 PM
Creating drop down list content control with "if" conditions Build paragraphs based on selecting "yes" from a content control jeffreybrown Word VBA 8 11-07-2018 04:02 PM
How to "hard link" two adjacent cells to a data validation drop down list? Geza59 Excel 10 10-19-2012 11:56 AM
How to edit the "Format" and the "show level" of an EXISTING table of content? Jamal NUMAN Word 2 08-14-2011 10:46 AM
Creating drop down list content control with "if" conditions How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 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