Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2020, 02:43 AM
ashbee ashbee is offline Not changing a content control if re-entered and Userform pops up. Windows 10 Not changing a content control if re-entered and Userform pops up. Office 2016
Novice
Not changing a content control if re-entered and Userform pops up.
 
Join Date: Jan 2020
Posts: 3
ashbee is on a distinguished road
Default Not changing a content control if re-entered and Userform pops up.

Hello there,

I'm hoping someone can help. I have a Word form that uses Greg Maxey's really helpful guide on how to get a multi-select list in Word. Currently, if the user re-enters the content control, any previous selections they make are cleared so they have to re-select them, what I'm trying to achieve is either:



1. if they re-enter the control it either re-loads what they've already selected into the list allowing them to add/remove any choices

OR

2. add another command button to the userform which allows them to leave without making any changes to what is already contained in the content control.

In a bid to trap any errors, I've removed the userform's Windows Close icon as if the user did not make any choices and tried to exit this way - they were taken to the code window to resolve the error. I also disabled the Confirm Selection button until the user makes a selection as this also created an error if the user clicked it before making a selection.

I've attached a sample of my form in the hope someone might be able to help with either of the two scenarios.
Attached Files
File Type: docm multiselect userform.docm (63.3 KB, 8 views)
Reply With Quote
  #2  
Old 01-26-2020, 10:44 AM
gmaxey gmaxey is offline Not changing a content control if re-entered and Userform pops up. Windows 10 Not changing a content control if re-entered and Userform pops up. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

ashbee,


Personally, I prefer list written out as a statement to be comma separated and the last item separated with " and ". I don't know why you used a function to return a string and then that string wasn't used.

Here is a revision to the code and the document is attached.

Code:
Public Sub SelectItems(oCC As ContentControl)
Dim oFrm As frmSelect
Dim arrText() As String, strText As String
Dim lngList As Long, lngItem As Long, lngSelected As Long
Dim arrList() As String
  Set oFrm = New frmSelect
  With oFrm
    .ListBox1.AddItem "Wheelchair Access"
    .ListBox1.AddItem "Note Taker"
    .ListBox1.AddItem "No"
    If Not oCC.ShowingPlaceholderText Then
      strText = Replace(oCC.Range.Text, ", ", "~")
      strText = Replace(strText, " and ", "~")
      arrList = Split(strText, "~")
      For lngItem = 0 To UBound(arrList)
        For lngList = lngItem To .ListBox1.ListCount - 1
          If .ListBox1.List(lngList) = Trim(arrList(lngItem)) Then
            .ListBox1.Selected(lngList) = True
          End If
        Next lngList
      Next lngItem
    End If
    .show
    If .Tag = 0 Then
      GoTo lbl_Exit
    Else
      ReDim arrText(0)
      For lngList = 0 To .ListBox1.ListCount - 1
        If .ListBox1.Selected(lngList) Then
          ReDim Preserve arrText(lngList)
          arrText(lngList) = .ListBox1.List(lngList)
          lngSelected = lngSelected + 1
        End If
      Next lngList
      Select Case UBound(arrText)
        Case 0
          strText = arrText(0)
        Case 1
          strText = arrText(0) & " and " & arrText(1)
        Case Else
          For lngList = 0 To UBound(arrText) - 1
            If lngList = 0 Then
              strText = arrText(lngList)
            Else
              strText = strText & ", " & arrText(lngList)
            End If
          Next lngList
          strText = strText & " and " & arrText(UBound(arrText))
      End Select
      oCC.Range.Text = strText
    End If
  End With
lbl_Exit:
  Unload oFrm
  Set oFrm = Nothing: Set oCC = Nothing
  Exit Sub
End Sub
Attached Files
File Type: docm multiselect userform.docm (87.1 KB, 9 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 01-26-2020, 11:18 AM
ashbee ashbee is offline Not changing a content control if re-entered and Userform pops up. Windows 10 Not changing a content control if re-entered and Userform pops up. Office 2016
Novice
Not changing a content control if re-entered and Userform pops up.
 
Join Date: Jan 2020
Posts: 3
ashbee is on a distinguished road
Default

Hello Greg,

Thank you for taking the time to look at this - I had tried adding a third case when it should have been Case Else like you've used, I'll definitely try that next time.

I think I left the string in from some code I removed to de-anonymise the form - it all works wonderfully thank you so much. For some reason I've found it easier to create Userforms in Excel than Word (mostly in part to being able to have named groups and shapes) but I'm keen to try to recreate some of those forms in Word to try to understand what code needs to be modified where and when.

Again thank you - I appreciate your sharing your knowledge.
Reply With Quote
  #4  
Old 01-26-2020, 11:58 AM
ashbee ashbee is offline Not changing a content control if re-entered and Userform pops up. Windows 10 Not changing a content control if re-entered and Userform pops up. Office 2016
Novice
Not changing a content control if re-entered and Userform pops up.
 
Join Date: Jan 2020
Posts: 3
ashbee is on a distinguished road
Default

I've just discovered that adding the selection toolbar allows me to see the names of shapes in Word!! I should now be able to recreate my Excel forms more easily
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not changing a content control if re-entered and Userform pops up. Changing line background color depending on the content control value valaden Word VBA 1 11-21-2019 08:11 PM
Not changing a content control if re-entered and Userform pops up. Changing color of instructional text in a content control box Document Specialist Word 2 08-17-2018 05:25 AM
Not changing a content control if re-entered and Userform pops up. Show Userform when Content Control CheckBox ticked derajlance Word VBA 1 05-13-2016 01:55 PM
Have Text Entered in Content Control / PreDefined Field Populate Field in Footer bzowk Word 1 04-14-2016 11:50 AM
How-to: Add a quickpart, field or Building Block Gallery Content Control based on a UserForm HighSierra Word VBA 0 05-06-2015 08:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft