Log in

View Full Version : Combination of 2 types of dropdown list content control



elaineada75
04-22-2022, 10:08 PM
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

elaineada75
04-24-2022, 06:56 PM
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

gmaxey
04-27-2022, 07:30 PM
The content control title is either "NameofCompany" or "EditableC" It can't be both.

elaineada75
04-27-2022, 07:59 PM
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.

gmaxey
04-28-2022, 05:06 AM
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

elaineada75
04-28-2022, 05:45 AM
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

gmaxey
04-28-2022, 11:39 AM
ActiveDocument.SelectContentControlsByTitle("Owner1").Item(1).Range.Text = "Sch" Then

elaineada75
04-29-2022, 05:42 AM
Thanks so much, really appreciate it! It works!