New@VB
04-24-2024, 06:41 AM
I have a Word document (attached) where the user is to enter information about the status of several tasks. For each task the user is to select the status of the task from a content control dropdown list. Options are: "No issues" or "Issues found". If "Issues found" is selected, the user is to provide a description of the issue for that task in a textbox.
While the code works for the first task, it does not work for the content controls in the second task
What am I doing wrong?
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
If CCtrl.Title = "CCDDL" Then
With CCtrl.Range
Select Case .Text
Case "Issues found"
.Font.ColorIndex = wdRed
ActiveDocument.SelectContentControlsByTitle("CCTB")(1).SetPlaceholderText , , "Enter issues here"
Case Else
.Font.ColorIndex = wdBlack
ActiveDocument.SelectContentControlsByTitle("CCTB")(1).SetPlaceholderText , , ChrW(8203)
ActiveDocument.SelectContentControlsByTitle("CCTB")(1).Range.Text = vbNullString
End Select
End With
End If
End Sub
Private Sub Document_ContentControlOnExit2(ByVal CCtrl As ContentControl, Cancel As Boolean)
If CCtrl.Title = "CCDDL2" Then
With CCtrl.Range
Select Case .Text
Case "Issues found"
.Font.ColorIndex = wdRed
ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).SetPlaceholderText , , "Enter issues here"
Case Else
.Font.ColorIndex = wdBlack
ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).SetPlaceholderText , , ChrW(8203)
ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).Range.Text = vbNullString
End Select
End With
End If
End Sub
While the code works for the first task, it does not work for the content controls in the second task
What am I doing wrong?
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
If CCtrl.Title = "CCDDL" Then
With CCtrl.Range
Select Case .Text
Case "Issues found"
.Font.ColorIndex = wdRed
ActiveDocument.SelectContentControlsByTitle("CCTB")(1).SetPlaceholderText , , "Enter issues here"
Case Else
.Font.ColorIndex = wdBlack
ActiveDocument.SelectContentControlsByTitle("CCTB")(1).SetPlaceholderText , , ChrW(8203)
ActiveDocument.SelectContentControlsByTitle("CCTB")(1).Range.Text = vbNullString
End Select
End With
End If
End Sub
Private Sub Document_ContentControlOnExit2(ByVal CCtrl As ContentControl, Cancel As Boolean)
If CCtrl.Title = "CCDDL2" Then
With CCtrl.Range
Select Case .Text
Case "Issues found"
.Font.ColorIndex = wdRed
ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).SetPlaceholderText , , "Enter issues here"
Case Else
.Font.ColorIndex = wdBlack
ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).SetPlaceholderText , , ChrW(8203)
ActiveDocument.SelectContentControlsByTitle("CCTB2")(1).Range.Text = vbNullString
End Select
End With
End If
End Sub