Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-02-2021, 10:30 PM
cookietyrant cookietyrant is offline Content Controls - Multiple Drop Downs - VBA Windows 10 Content Controls - Multiple Drop Downs - VBA Office 2019
Novice
Content Controls - Multiple Drop Downs - VBA
 
Join Date: Aug 2021
Posts: 2
cookietyrant is on a distinguished road
Angry Content Controls - Multiple Drop Downs - VBA

Basically I have 2 Fields of which I want to have a drop down for with unique data the below code works perfectly for my Project manager section, but then when I want to run it against the engineer section it won't fill in the Engineer details section...I'm assuming there is some sort of join or piece of code I'm missing to get multiple drop downs utilizing the below code to act independent of each other.

I attached a screen shot of which may help show what I'm trying to do...

HTML Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String
With ContentControl
  If .tag = "ProjectManager" 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
HTML Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String
With ContentControl
  If .tag = "Engineer" 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

Attached Images
File Type: png Word Table.PNG (45.1 KB, 15 views)
Reply With Quote
  #2  
Old 08-02-2021, 11:21 PM
gmayor's Avatar
gmayor gmayor is offline Content Controls - Multiple Drop Downs - VBA Windows 10 Content Controls - Multiple Drop Downs - VBA Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can use case statements to identify the control and process accordingly. Note that both your examples populate contentcontrols(2), which seems improbable. Call the controls to be populated by their tags e.g. as follows.
You may find https://www.gmayor.com/insert_content_control_addin.htm useful


Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long
Dim strDetails As String
Dim oCC As ContentControl
    With ContentControl
        If .ShowingPlaceholderText = False Then
            Select Case .Tag
                Case Is = "ProjectManager"
                    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 i
                    Set oCC = ActiveDocument.SelectContentControlsByTag("Tag of the project manager details").Item(1)
                    oCC.Range.Text = strDetails
                Case Is = "Engineer"
                    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 i
                    Set oCC = ActiveDocument.SelectContentControlsByTag("Tag of the engineer details").Item(1)
                    oCC.Range.Text = strDetails
                Case Else
            End Select
        End If
    End With
    Set oCC = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-03-2021, 04:51 PM
cookietyrant cookietyrant is offline Content Controls - Multiple Drop Downs - VBA Windows 10 Content Controls - Multiple Drop Downs - VBA Office 2019
Novice
Content Controls - Multiple Drop Downs - VBA
 
Join Date: Aug 2021
Posts: 2
cookietyrant is on a distinguished road
Default

I'll give this a try tonight....my brain was fried and I haven't coded in 15 years lol
Reply With Quote
Reply

Tags
content controls, drop down list, word 2019



Similar Threads
Thread Thread Starter Forum Replies Last Post
Content Controls - Multiple Drop Downs - VBA Cascading drop-downs in Word with one parent menu and four dependent drop-downs mrstrawhand Word VBA 3 03-30-2020 06:08 AM
Populating multiple Content Controls after mail merge guiltyvictim Word VBA 3 07-30-2019 09:27 AM
Content Controls - Multiple Drop Downs - VBA Content Controls (Drop Down copy and paste), and XML mapping dezdelaina Word 3 03-05-2018 06:50 PM
Content Controls - Multiple Drop Downs - VBA 2 drop down list content controls danfookes Word VBA 2 03-02-2018 02:05 AM
Content Controls - Multiple Drop Downs - VBA Inserting multiple content controls for a date jeffreybrown Word 2 05-09-2016 05:53 PM

Other Forums: Access Forums

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