How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Greg Maxey Your Own Question
Greg Maxey
Greg Maxey, Consultant\Microsoft Word Expert
Category: General
Satisfied Customers: 62
Experience:  Microsoft Word Most Valuable Professional (6 years)
Type Your Question Here...
Greg Maxey is online now
A new question is answered every 9 seconds

Ask a Microsoft Word Question What coding would be required

Resolved Question:

Ask a Microsoft Word Question
> What coding would be required to get a drop down box contents to change depending on the selection in a previous drop down box.
Submitted: 7 years ago.
Category: General
Expert:  Greg Maxey replied 7 years ago.


Customer: replied 7 years ago.
I have tried that already but the macro stops on the first line of the programme upon reaching 'secondaryDD'. If it helps I am using Word 2007 so the choices of drop down I have are 'Combo Box' or 'Drop Down List'
Expert:  Greg Maxey replied 7 years ago.

The link I referenced answers your general question. I would suppose the macro stops on the line you indicate because you have not named the secondary dropdown "secondaryDD" and you are using Word2007 content controls vice a legacy formfield dropdown.


The code for Word 2007 and contentControls is very complicated because of a bug in Word2007 that Microsoft has neglected to fix for over 5 years. The OnExit event needed for this process will fire twice if the "Developer Tab" is not displayed.


You will need this code in a standard module:


Option Explicit
Public Const CHILDID_SELF As Long = &H0&
Public Const STATE_SYSTEM_INVISIBLE As Long = &H8000&
Public Const STATE_SYSTEM_SELECTED As Long = &H2&
Public Enum RoleNumber
End Enum
Private Enum NavigationDirection
End Enum
Private Declare Function AccessibleChildren Lib "oleacc.dll" _
(ByVal paccContainer As Object, ByVal iChildStart As Long, _
ByVal cChildren As Long, rgvarChildren As Variant, pcObtained As Long) As Long
Public Function GetAccessible(Element As IAccessible, RoleWanted As RoleNumber, _
NameWanted As String, Optional GetClient As Boolean) As IAccessible
Dim ChildrenArray() As Variant
Dim Child As IAccessible
Dim ndxChild As Long
Dim ReturnElement As IAccessible
If Element.accRole(CHILDID_SELF) = RoleWanted And Element.accName(CHILDID_SELF) = NameWanted Then
Set ReturnElement = Element
Else ' not found yet
ChildrenArray = GetChildren(Element)
If (Not ChildrenArray) <> True Then
For ndxChild = LBound(ChildrenArray) To UBound(ChildrenArray)
If TypeOf ChildrenArray(ndxChild) Is IAccessible Then
Set Child = ChildrenArray(ndxChild)
Set ReturnElement = GetAccessible(Child, RoleWanted, NameWanted)
If Not ReturnElement Is Nothing Then Exit For
End If ' Child is IAccessible
Next ndxChild
End If ' there are children
End If ' still looking
If GetClient Then
Set ReturnElement = ReturnElement.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)
End If
Set GetAccessible = ReturnElement
End Function
Private Function GetChildren(Element As IAccessible) As Variant()
Const FirstChild As Long = 0&
Dim NumChildren As Long
Dim NumReturned As Long
Dim ChildrenArray() As Variant
NumChildren = Element.accChildCount
If NumChildren > 0 Then
ReDim ChildrenArray(NumChildren - 1)
AccessibleChildren Element, FirstChild, NumChildren, ChildrenArray(0), NumReturned
End If
GetChildren = ChildrenArray
End Function


You will need this code in the ThisDocument module:


Option Explicit
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim RibbonTab As IAccessible
Set RibbonTab = GetAccessible(CommandBars("Ribbon"), ROLE_SYSTEM_PAGETAB, "Developer")
If Not RibbonTab Is Nothing Then
RibbonTab.accDoDefaultAction CHILDID_SELF
MsgBox "Designated Tab is unavailable"
End If
End If
End Sub

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Select Case CC.Title
Case "productCode"
Select Case CC.Range.Text
Case "1234"
ActiveDocument.SelectContentControlsByTitle("Product Description").Item(1).Range.Text = "Describe product 1234 here"
Case "9876"
ActiveDocument.SelectContentControlsByTitle("Product Description").Item(1).Range.Text = "Describe product 9876 here"
Case "5555"
ActiveDocument.SelectContentControlsByTitle("Product Description").Item(1).Range.Text = "Describe product 5555 here"
Case Else
ActiveDocument.SelectContentControlsByTitle("Product Description").Item(1).Range.Text = ""
End Select
End Select
End Sub



Greg Maxey and 49 other General Specialists are ready to help you