Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2018, 10:36 PM
krishnamurthy.ka2810 krishnamurthy.ka2810 is offline Selection of a dropdown creates another dropdown wih the list Windows 10 Selection of a dropdown creates another dropdown wih the list Office 2016
Novice
Selection of a dropdown creates another dropdown wih the list
 
Join Date: Apr 2018
Posts: 6
krishnamurthy.ka2810 is on a distinguished road
Default Selection of a dropdown creates another dropdown wih the list

I am using the below VB code to auto fill text based on drop down using content control. I need to also create a dropdown based on another drop down selection. How do I include in the piece of code. Please help.

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String
With ContentControl

If .Title = "Company" Then
For m = 1 To .DropdownListEntries.Count
If UCase(.DropdownListEntries(m).Text) = UCase(.Range.Text) Then
Select Case m
Case 1
StrDetails = ""
Case 2
StrDetails = "Singapore"
Case 3
StrDetails = "Singapore"
Case 4
StrDetails = "Singapore"
Case 5
StrDetails = "Malaysia"
Case 6
StrDetails = "Thailand"
Case 7
StrDetails = "Cambodia"
Case 8
StrDetails = "Philippines"
Case Else: StrDetails = " "
End Select


End If
Next
ActiveDocument.SelectContentControlsByTitle("Count ry").Item(1).Range.Text = StrDetails

End If
End With
End Sub
Reply With Quote
  #2  
Old 04-26-2018, 11:44 PM
gmayor's Avatar
gmayor gmayor is offline Selection of a dropdown creates another dropdown wih the list Windows 10 Selection of a dropdown creates another dropdown wih the list Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

Use the # command to format your code with tags in the forum.

You probably want something like the following. I have only filled 1 case. Add the values to the others as appropriate. Rename the title of the dropdown field in question to match your document.

You may find https://www.gmayor.com/insert_content_control_addin.htm useful.

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, m As Long
Dim strDetails As String
Dim oCC As ContentControl
    With ContentControl
        If ContentControl.ShowingPlaceholderText = False Then
            If .Title = "Company" Then
                Set oCC = ActiveDocument.SelectContentControlsByTitle("CountryDropDownName").Item(1)
                For m = 1 To .DropdownListEntries.Count
                    If UCase(.DropdownListEntries(m).Text) = UCase(.Range.Text) Then
                        Select Case m
                            Case 1
                                'This is the prompt and should not trip the macro
                                strDetails = " "
                                oCC.DropdownListEntries.Clear
                            Case 2
                                strDetails = "Singapore"
                                With oCC.DropdownListEntries
                                    .Clear
                                    .Add "Item1", "Item1"
                                    .Add "Item2", "Item2"
                                    'etc
                                End With
                            Case 3
                                strDetails = "Singapore"
                            Case 4
                                strDetails = "Singapore"
                            Case 5
                                strDetails = "Malaysia"
                            Case 6
                                strDetails = "Thailand"
                            Case 7
                                strDetails = "Cambodia"
                            Case 8
                                strDetails = "Philippines"
                            Case Else
                                strDetails = " "
                                 oCC.DropdownListEntries.Clear
                        End Select
                        Exit For
                    End If
                Next
                ActiveDocument.SelectContentControlsByTitle("Country").Item(1).Range.Text = strDetails
            End If
        End If
    End With
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
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selection of a dropdown creates another dropdown wih the list Change color according with dropdown selection spk Word VBA 43 07-31-2022 03:51 PM
Selection of a dropdown creates another dropdown wih the list Multiple Selection Dropdown list ajanson Word VBA 36 07-15-2019 08:16 PM
Selection of a dropdown creates another dropdown wih the list Auto text after selection from Dropdown menu trainsy Word 2 06-04-2014 04:43 AM
block selection in dropdown list Intruder Excel 2 01-10-2013 10:20 AM
Selection of a dropdown creates another dropdown wih the list Dropdown selection value coconutt Word VBA 5 09-13-2012 05:23 PM

Other Forums: Access Forums

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