View Single Post
 
Old 04-23-2025, 02:22 PM
CompletelyLost CompletelyLost is offline Windows 11 Office 2021
Novice
 
Join Date: Apr 2025
Posts: 4
CompletelyLost is on a distinguished road
Default

Greg,

I tried the code and based on what you had, I assumed I had to put the "Title" of every box that I was associating the original code with as a Case since you used the title Demo1. Now I get a Run-time error '6124' that says I'm not allowed to edit this selection because it is protected. Yes, I enabled protection to Form Only, to test for how a user will interact. No, the box locking contents from being edited is not checked. This is what I did:

Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim oDLE As ContentControlListEntry
  With CCtrl
    Select Case .Title
    Case "Address"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
    Case "City"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
   Case "Phone"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
   Case "Fax"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
   Case "License"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
   Case "Contractor"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          ActiveDocument.SelectContentControlsByTitle("Company").Item(1).Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
    End Select
  End With
End Sub
All other dropdown boxes have the same Display Name and Value. Suggestions?

Last edited by macropod; 04-23-2025 at 04:29 PM. Reason: Added code tags - again
Reply With Quote