Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #136  
Old 05-22-2021, 02:32 PM
macropod's Avatar
macropod macropod is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See post #71 in this thread: https://www.msofficeforums.com/word-...tml#post120392
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #137  
Old 11-06-2021, 10:37 AM
enci101 enci101 is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2019
Novice
 
Join Date: May 2021
Location: Frankfurt, Germany
Posts: 2
enci101 is on a distinguished road
Default

Everything works so far, if I only use one table row. However, when I duplicate the row using ContentControl, the macros get messed up and they start to fill out the wrong fields in the wrong rows. Does anyone have an idea, how to fix this?
Reply With Quote
  #138  
Old 11-06-2021, 05:17 PM
Guessed's Avatar
Guessed Guessed is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists 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

There are 136 previous posts in this thread and I have no idea on what you are looking at. I suggest you start a new thread and post your document so someone can look at what your issue might be.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #139  
Old 04-28-2022, 07:14 PM
manishhb2000 manishhb2000 is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2016
Novice
 
Join Date: Apr 2022
Posts: 1
manishhb2000 is on a distinguished road
Default

Hi Macropod, thanks for this. when i am recreating this code on a different word file, i am getting an error on this line .
ActiveDocument.ContentControls(2).Range.Text = StrDetails

I basically copied same code changed the Title to reflect my new title which is "Office". What am i missing? Appreciate your help



Full Code here:
Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String
With ContentControl
  If .Title = "Office" Then
  For i = 1 To .DropdownListEntries.Count
    If .DropdownListEntries(i).Text = .Range.Text Then
      StrDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11))
      Exit For
    End If
  Next
  ActiveDocument.ContentControls(2).Range.Text = StrDetails
  End If
End With
End Sub

Last edited by macropod; 04-29-2022 at 06:23 PM. Reason: Added code tags
Reply With Quote
  #140  
Old 04-29-2022, 06:24 PM
macropod's Avatar
macropod macropod is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The output goes to the second content control in the document, which must be a Rich Text content control. Is that how your document is configured?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #141  
Old 10-11-2022, 02:47 PM
bil_san1 bil_san1 is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2016
Novice
 
Join Date: Oct 2022
Posts: 12
bil_san1 is on a distinguished road
Default

Hi,

I am new to Macros.. I was able to change the drop down items to and its result.

But I would like to change the First Content Control titles from "Client Details" to "Please Select" and the second Content Control Title from "Client" to "Blank"

I have tried to change in the properties and in the code too but it gives me

Run Time Error "6189"

Also I would like to result to be in other place not close to drop down menu.

Is it possible.

Thanks
Reply With Quote
  #142  
Old 10-11-2022, 03:13 PM
macropod's Avatar
macropod macropod is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by bil_san1 View Post
But I would like to change the First Content Control titles from "Client Details" to "Please Select" and the second Content Control Title from "Client" to "Blank"

I have tried to change in the properties and in the code too but it gives me

Run Time Error "6189"
You need to change the titles in both the document and the code.
Quote:
Originally Posted by bil_san1 View Post
Also I would like to result to be in other place not close to drop down menu.
The output content control can be located anywhere in the document. If you want different parts of the output going to different content controls, see, for example, post #33 in this thread: https://www.msofficeforums.com/word-...html#post90264.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #143  
Old 10-11-2022, 03:39 PM
bil_san1 bil_san1 is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2016
Novice
 
Join Date: Oct 2022
Posts: 12
bil_san1 is on a distinguished road
Default Please ignore my post. I have found answer in another post of yours. My answer was formfield

Quote:
Originally Posted by macropod View Post
You need to change the titles in both the document and the code.

I have changed in both code and properties box of both content control. It gives me an error when I click out of it. I have attached the file. Kindly have a look and guide me where I am making mistake.

The output content control can be located anywhere in the document. If you want different parts of the output going to different content controls, see, for example, post #33 in this thread: https://www.msofficeforums.com/word-...html#post90264.
I just want the complete result after a break of 1 or two lines.
Attached Files
File Type: docm Content Controls - Dropdown Dependent Text.docm (31.2 KB, 8 views)

Last edited by bil_san1; 10-12-2022 at 02:55 AM. Reason: Found the answer in another post
Reply With Quote
  #144  
Old 10-12-2022, 03:07 AM
gmaxey gmaxey is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Paul,


This is a very long thread. Perhaps I've shared this with you before but not sure. Have you considered mapping the two controls in your example file (post #2). If you do, your code is reduced to:


Code:
Private Sub Document_ContentControlBeforeContentUpdate(ByVal ContentControl As ContentControl, Content As String)
  With ContentControl
    If .Title = "Client" Then
      .XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:ClientDetails[1]").Text = _
        Replace(.XMLMapping.CustomXMLPart.SelectSingleNode("/ns0:CC_Map_Root[1]/ns0:Client[1]").Text, "|", vbCr)
    End If
  End With
lbl_Exit:
  Exit Sub
End Sub

with no requirement to exit the Client CC
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #145  
Old 07-17-2023, 10:20 PM
Atzhel Atzhel is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2019
Novice
 
Join Date: Mar 2023
Location: Peru
Posts: 4
Atzhel is on a distinguished road
Default

Hi, I'm kinda new to macros on word. So, I managed to do a two-level dependent dropdown list with contentcontrol boxes. I want to make third level but this one is autopopulated. I saw the method with values, but because it's a dependent dropdown list there are no values for the second level. I've looked through all posts on this thread but it seems there's no answer for what I need.

I would really be thankful if someone can help me.

This is the code I've got so far, what I want is that after I select the second dropdown another control content box gets filled on its own with a set value.

Let's say I select
Quote:
Obtiene información de textos orales
from

Code:
 Case "Se comunica oralmente en inglés como lengua extranjera"
        StrOut = "Obtiene información de textos orales;Infiere e interpreta información de textos orales;Adecúa, organiza y desarrolla las ideas de forma coherente y cohesionada;Utiliza recursos no verbales y paraverbales de forma estratégica;Interactúa estratégicamente con distintos interlocutores;Reflexiona y evalúa la forma, el contenido y el contexto del texto oral"
then I want a controlcontent box to automatically populate with a set text.

Code:
Option Explicit
Dim StrOption As String

Private Sub Document_ContentControlOnEnter(ByVal CCtrl As ContentControl)
StrOption = CCtrl.Range.Text
End Sub

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim i As Long, StrOut As String
With CCtrl
  If .Title = "Competencias" Then
    If StrOption = .Range.Text Then Exit Sub
    Select Case .Range.Text
      Case "Se comunica oralmente en inglés como lengua extranjera"
        StrOut = "Obtiene información de textos orales;Infiere e interpreta información de textos orales;Adecúa, organiza y desarrolla las ideas de forma coherente y cohesionada;Utiliza recursos no verbales y paraverbales de forma estratégica;Interactúa estratégicamente con distintos interlocutores;Reflexiona y evalúa la forma, el contenido y el contexto del texto oral"
      Case "Lee diversos tipos de textos en inglés como lengua extranjera"
        StrOut = "Obtiene información del texto escrito;Infiere e interpreta información del texto escrito;Reflexiona y evalúa la forma, el contenido y contexto del texto"
      Case "Escribe diversos tipos de textos en inglés como lengua extranjera"
        StrOut = "Adecúa el texto a la situación comunicativa;Organiza y desarrolla las ideas de forma coherente y cohesionada;Utiliza convenciones del lenguaje escrito de forma pertinente;Reflexiona y evalúa la forma, el contenido y contexto del texto escrito"
      Case Else
        .Type = wdContentControlText
        .Range.Text = ""
        .Type = wdContentControlDropdownList
    End Select
    With ActiveDocument.SelectContentControlsByTitle("Capacidades")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
    With ActiveDocument.SelectContentControlsByTitle("Capacidades2")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
    With ActiveDocument.SelectContentControlsByTitle("Capacidades3")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
    With ActiveDocument.SelectContentControlsByTitle("Capacidades4")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
  End If
  If .Title = "Competencias2" Then
    If StrOption = .Range.Text Then Exit Sub
    Select Case .Range.Text
      Case "Se comunica oralmente en inglés como lengua extranjera"
        StrOut = "Obtiene información de textos orales;Infiere e interpreta información de textos orales;Adecúa, organiza y desarrolla las ideas de forma coherente y cohesionada;Utiliza recursos no verbales y paraverbales de forma estratégica;Interactúa estratégicamente con distintos interlocutores;Reflexiona y evalúa la forma, el contenido y el contexto del texto oral"
      Case "Lee diversos tipos de textos en inglés como lengua extranjera"
        StrOut = "Obtiene información del texto escrito;Infiere e interpreta información del texto escrito;Reflexiona y evalúa la forma, el contenido y contexto del texto"
      Case "Escribe diversos tipos de textos en inglés como lengua extranjera"
        StrOut = "Adecúa el texto a la situación comunicativa;Organiza y desarrolla las ideas de forma coherente y cohesionada;Utiliza convenciones del lenguaje escrito de forma pertinente;Reflexiona y evalúa la forma, el contenido y contexto del texto escrito"
      Case Else
        .Type = wdContentControlText
        .Range.Text = ""
        .Type = wdContentControlDropdownList
    End Select
    With ActiveDocument.SelectContentControlsByTitle("Capacidades5")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
    With ActiveDocument.SelectContentControlsByTitle("Capacidades6")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
    With ActiveDocument.SelectContentControlsByTitle("Capacidades7")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
    With ActiveDocument.SelectContentControlsByTitle("Capacidades8")(1)
      .DropdownListEntries.Clear
      .DropdownListEntries.Add .PlaceholderText
      For i = 0 To UBound(Split(StrOut, ";"))
        .DropdownListEntries.Add Split(StrOut, ";")(i)
      Next
      .Type = wdContentControlText
      .Range.Text = ""
      .Type = wdContentControlDropdownList
    End With
  End If
End With
Application.ScreenUpdating = True
End Sub
Sorry if the message is too long or I go around the topic too many times, I'm no expert at programming and I want to be as clear as possible. Again, thank you in advance for any response.
Reply With Quote
  #146  
Old 07-18-2023, 05:43 PM
Guessed's Avatar
Guessed Guessed is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists 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

For someone who is 'kinda new to macros' and speaks multiple languages you have done a remarkable job with the code. Well done.

However you haven't explained particularly well your actual question with regards to a third level. You also didn't post a sample document so we can't see what your structure might be for that third level.

I've looked at the code you provided and decided that it is needlessly repetitive and can be streamlined to make things clearer. So I created a sample doc and set up some loops to achieve what I think your code was already doing in a less repetitive way. This makes use of both the Title and Tag properties of the CCs so that groups of related CCs can be looped through in the code. If this aligns with your actual document, then perhaps you can post a sample document and explain more clearly what the third level should do when the second level is changed.

I suspect it can be even more streamlined if your document is setup with Repeating Sections which is what it appears you are trying to do.

This is the code I adapted from your posted code so that it works with a document with CCs set up with both Tag and Title attributes.
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
  Application.ScreenUpdating = False
  Dim i As Long, StrOut As String, aCC As ContentControl, arrOut() As String
  With CCtrl
    If .Tag = "Trigger" Then
      If StrOption = .Range.Text Then Exit Sub
      Select Case .Range.Text
        Case "Se comunica oralmente en inglés como lengua extranjera"
          StrOut = "Obtiene información de textos orales;Infiere e interpreta información de textos orales;Adecúa, organiza y desarrolla las ideas de forma coherente y cohesionada;Utiliza recursos no verbales y paraverbales de forma estratégica;Interactúa estratégicamente con distintos interlocutores;Reflexiona y evalúa la forma, el contenido y el contexto del texto oral"
        Case "Lee diversos tipos de textos en inglés como lengua extranjera"
          StrOut = "Obtiene información del texto escrito;Infiere e interpreta información del texto escrito;Reflexiona y evalúa la forma, el contenido y contexto del texto"
        Case "Escribe diversos tipos de textos en inglés como lengua extranjera"
          StrOut = "Adecúa el texto a la situación comunicativa;Organiza y desarrolla las ideas de forma coherente y cohesionada;Utiliza convenciones del lenguaje escrito de forma pertinente;Reflexiona y evalúa la forma, el contenido y contexto del texto escrito"
        Case Else
          .Type = wdContentControlText
          .Range.Text = ""
          .Type = wdContentControlDropdownList
      End Select
      arrOut = Split(StrOut, ";")
      For Each aCC In ActiveDocument.SelectContentControlsByTag(CCtrl.Title)
        aCC.DropdownListEntries.Clear
        aCC.DropdownListEntries.Add .PlaceholderText
        aCC.Type = wdContentControlText
          aCC.Range.Text = ""
        aCC.Type = wdContentControlDropdownList
        If Not CCtrl.ShowingPlaceholderText Then
          For i = 0 To UBound(arrOut)
            aCC.DropdownListEntries.Add arrOut(i)
          Next
        End If
      Next aCC
    End If
  End With
  Application.ScreenUpdating = True
End Sub
Attached Files
File Type: docm DependentCCs.docm (37.4 KB, 4 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #147  
Old 07-18-2023, 08:10 PM
Atzhel Atzhel is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2019
Novice
 
Join Date: Mar 2023
Location: Peru
Posts: 4
Atzhel is on a distinguished road
Default

Thank you so much! This is a lot less than before, I totally forgot about OR XD.

Anyways, the third level is supposed to not give me an option, each contentbox of the second level has another control box and depending on which option I choose from the second level, it has to return an established text for just one box.

I will upload my document with the updated code. Just a thing I noticed, the document you sent works fine, but mine doesn't, if I select "Se comunica oralmente" in the first level then the second level for both sets show me the second level just for that option, but if I choose any other it works just fine. I even copied the same boxes from your document and the code and nothing.
Attached Files
File Type: docm Sample.docm (56.3 KB, 3 views)
Reply With Quote
  #148  
Old 07-19-2023, 07:09 AM
gmaxey gmaxey is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

See attached
Attached Files
File Type: docm Sample.docm (58.5 KB, 5 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #149  
Old 07-19-2023, 08:07 AM
Atzhel Atzhel is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2019
Novice
 
Join Date: Mar 2023
Location: Peru
Posts: 4
Atzhel is on a distinguished road
Default

Thank you for the document, now the second level works fine, but the third doesn't.

As I said, I want to automatically populate the third level depending on what I chose in the second one.

Still, thank you a lot. I will upload it again and see what else can be done
Attached Files
File Type: docm Sample.docm (57.6 KB, 3 views)
Reply With Quote
  #150  
Old 07-19-2023, 08:19 AM
gmaxey gmaxey is offline Multiple entries in dropdown lists Windows 10 Multiple entries in dropdown lists Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

See attached
Attached Files
File Type: docm Sample.docm (59.6 KB, 18 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple entries in dropdown lists Delete Multiple Entries dudeabides Office 1 07-04-2011 02:49 AM
Multiple task lists and multiple calendars kballing Outlook 0 01-18-2011 10:23 AM
Creating Multiple Contact Lists meltee78 Outlook 1 01-03-2011 09:45 PM
multiple calendar entries across a group halfhearted Outlook 0 10-11-2009 12:13 PM
Word Forms : Dropdown lists wferaera45 Word 0 04-06-2006 03:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:40 AM.


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