Consulting

Results 1 to 8 of 8

Thread: Combination of 2 types of dropdown list content control

  1. #1

    Combination of 2 types of dropdown list content control

    Can anyone advise me how to combine 2 dropdown list: 1 dropdown list with conditional content, another dropdown list with bookmarks. The below code cannot work and the row was cut away after updating the 2nd dropdown list.

    Thanks.


    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)Application.ScreenUpdating = False
    Dim i As Long, StrDetails As String
    
    
    'Dropdown list 1
    
    
    With ContentControl
      If .Title = "NameofCompany" Then
        For i = 1 To .DropdownListEntries.Count
          If .DropdownListEntries(i).Text = .Range.Text Then
            StrDetails = .DropdownListEntries(i).Value
            Exit For
          End If
        Next
        If StrDetails = "" Then StrDetails = "||"
        With ActiveDocument.SelectContentControlsByTitle("Address")(1)
          .LockContents = False
          .Range.Text = Split(StrDetails, "|")(0)
          .LockContents = True
        End With
        With ActiveDocument.SelectContentControlsByTitle("Owner")(1)
          .LockContents = False
          .Range.Text = Split(StrDetails, "|")(1)
          .LockContents = True
        End With
        End If
    End With
    Application.ScreenUpdating = True
      
    'dropdown list 2 - with bookmark
    
    
      Case ContentControl.Title
       Case "EditableC"
          Select Case ContentControl.Range.Text
            Case "YES": InsertBB_atBookmarkRange_Range "bmEditable", "EditableYesPara"
            Case "NO": InsertBB_atBookmarkRange_Range "bmEditable", "EditableNoPara"
            Case Else: InsertBB_atBookmarkRange_Range "bmEditable"
          End Select
      End Select
    lbl_Exit:
      Exit Sub
      
    
    
    End Sub

  2. #2
    Hi I have made adjustment to insert autotext instead of building blocks, but i still could not get it right. Can anyone tell me what is wrong with my code? The 2nd dropdown list not able to update the bookmark. May i know what is wrong here? Any help is appreciated. Thanks.

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Application.ScreenUpdating = False
    Dim i As Long, StrDetails As String
     
    With ContentControl
      If .Title = "NameofCompany" Then
        For i = 1 To .DropdownListEntries.Count
          If .DropdownListEntries(i).Text = .Range.Text Then
            StrDetails = .DropdownListEntries(i).Value
            Exit For
          End If
        Next
        If StrDetails = "" Then StrDetails = "||"
        With ActiveDocument.SelectContentControlsByTitle("Address")(1)
          .LockContents = False
          .Range.Text = Split(StrDetails, "|")(0)
          .LockContents = True
        End With
        With ActiveDocument.SelectContentControlsByTitle("Owner")(1)
          .LockContents = False
          .Range.Text = Split(StrDetails, "|")(1)
          .LockContents = True
        End With
     
      If .Title = "EditableC" Then
        Select Case ContentControl.Title
        Case "YES": Call InsertAutoTextEntry
        Case Else: Call InsertAutoTextEntryNo
     
      End Select
     
      End If
        End If
     
    End With
     
     
    Application.ScreenUpdating = True
    End Sub
     
    Sub InsertAutoTextEntry()
     
    Dim rngDoc1 As Range
     
    Set rngDoc1 = ActiveDocument.Range.Bookmarks("bmEditable").Range
    ActiveDocument.AttachedTemplate.AutoTextEntries("EditableYes").Insert _
    Where:=rngDoc1, RichText:=True
     
    End Sub
     
    Sub InsertAutoTextEntryNo()
     
    Dim rngDoc1 As Range
     
    Set rngDoc1 = ActiveDocument.Range.Bookmarks("bmEditable").Range
    ActiveDocument.AttachedTemplate.AutoTextEntries("EditableNo").Insert _
    Where:=rngDoc1, RichText:=True
    
    End Sub

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    The content control title is either "NameofCompany" or "EditableC" It can't be both.
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    I have 2 content control, one is dropdown list (NameofCompany) and the other one is a checkbox (EditableC).
    How to merge these 2 together in the macro?
    Sorry i am still trying very hard to learn to write macro in words. It is very different in excel.
    Thanks a lot.

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    You have an event:
    Document_ContentControlOnExit

    It fires when you exit a document content control.

    In that event, you have and If ... End If Statement.

    You have told your macro to do something "IF" the Content Control title is "NameofCompany".

    If the title isn't "NameofCompany" then the event does nothing e.g., it completely ignores the part of your code associated with "EditableC"

    That is what you have programmed the event to do.

    If you want to process both CCs then something like this:

    Select Case ContentControl.Title
    Case "NameofCompany"
    Do this
    Case "EditableC"
    Do something else
    End Select
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    Hi Hi
    I somehow got it work, but when i add it another condition for the checkbox, it stops working.
    Where did i get it wrong?
    Pl help me. Thanks a lot.

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
     
    Application.ScreenUpdating = False
    Dim i As Long, StrDetails As String
     
      Dim oRng As Range
     
    With ContentControl
     
     
      If .Title = "NameofCompany" Then
        For i = 1 To .DropdownListEntries.Count
          If .DropdownListEntries(i).Text = .Range.Text Then
            StrDetails = .DropdownListEntries(i).Value
            Exit For
          End If
        Next
        If StrDetails = "" Then StrDetails = "||"
        With ActiveDocument.SelectContentControlsByTitle("Address")(1)
          .LockContents = False
          .Range.Text = Split(StrDetails, "|")(0)
          .LockContents = True
        End With
        With ActiveDocument.SelectContentControlsByTitle("Owner1")(1)
          .LockContents = False
          .Range.Text = Split(StrDetails, "|")(1)
          .LockContents = True
        End With
      End If
     
      End With
     
        Set oRng = ActiveDocument.Bookmarks("bmEditSch").Range
        Set iRng = ActiveDocument.Bookmarks("bmEditAut").Range
       
        If ContentControl.Tag = "Checkbox1" Then
               If ContentControl.Checked = True Then
                If ActiveDocument.ContentControls("Owner1") = Sch Then
                oRng.Font.Hidden = False
                iRng.Font.Hidden = True
            Else
                oRng.Font.Hidden = True
                iRng.Font.Hidden = False
            End If
        End If
       End If
     
      
     
    ActiveDocument.Fields.Update
    Application.ScreenUpdating = True
     
    End Sub

  7. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    ActiveDocument.SelectContentControlsByTitle("Owner1").Item(1).Range.Text = "Sch" Then
    Greg

    Visit my website: http://gregmaxey.com

  8. #8
    Thanks so much, really appreciate it! It works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •