Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-07-2016, 01:56 AM
highrise955 highrise955 is offline Dropdownlist-Parsing values to various ContentControls Windows 10 Dropdownlist-Parsing values to various ContentControls Office 2013
Advanced Beginner
Dropdownlist-Parsing values to various ContentControls
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default Dropdownlist-Parsing values to various ContentControls

Hi All!

I have a combobox with multiple entries on my template. Each entry has multiple values separated by the "|" symbol. When the template loads, a userform pops up asking the user to type in a number. That number is then put into the combobox in my document. I then want the various values for the combobox entry (assuming they typed in a number that is listed in the combobox) to be placed into various contentcontrols in my document.

I know how to do it if the entry has only ONE value but I'm a little confused with multiple values. Here is the code I am currently using to act on just ONE value for an unrelated action...



Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String
With ContentControl
  If .Title = "Client" Then
  For i = 1 To .DropdownListEntries.Count
    If .DropdownListEntries(i).Text = .Range.Text Then
      StrDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11))
      Exit For
    End If
  Next
  ActiveDocument.ContentControls(2).Range.Text = StrDetails
  End If
End With
End Sub
I hope I am explaining this correctly.
Reply With Quote
  #2  
Old 03-07-2016, 02:25 AM
macropod's Avatar
macropod macropod is offline Dropdownlist-Parsing values to various ContentControls Windows 7 64bit Dropdownlist-Parsing values to various ContentControls Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps you should study the thread your code was lifted from more closely: https://www.msofficeforums.com/word-...own-lists.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-07-2016, 02:55 AM
highrise955 highrise955 is offline Dropdownlist-Parsing values to various ContentControls Windows 10 Dropdownlist-Parsing values to various ContentControls Office 2013
Advanced Beginner
Dropdownlist-Parsing values to various ContentControls
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Perhaps you should study the thread your code was lifted from more closely: https://www.msofficeforums.com/word-...own-lists.html

I did and I was thinking the following code in post #33 of that thread might be what I am looking for...

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String
With ContentControl
  If .Title = "Client" Then
    For i = 1 To .DropdownListEntries.Count
      If .DropdownListEntries(i).Text = .Range.Text Then
        StrDetails = Replace(.DropdownListEntries(i).Value, "|", Chr(11))
        Exit For
      End If
    Next
    With ActiveDocument
      .SelectContentControlsByTitle("ClientAddress").Item(1).Range.Text = StrDetails
      If StrDetails <> " " Then StrDetails = _
      .SelectContentControlsByTitle("Client").Item(1).Range.Text & Chr(11) & StrDetails 
      .SelectContentControlsByTitle("ClientDetails").Item(1).Range.Text = StrDetails
    End With
  End If
End With
End Sub
But I just can't seem to understand how to direct the different values to the various contentcontrols. I'm sure it's staring at me right in the face but I'm just not getting it.

For example, let's say the user types in the number 4444-333-55555.

And that number in the combobox (named: "Drawing Number") has the following values:

Laser Assembly RH|Steel, Polycarb|Rev N

I want the first value to go to a contentcontrol named "Product Description" and the second value to go to a contrentcontrol named "Material" and so on...

Thanks for any input you can offer.
Reply With Quote
  #4  
Old 03-07-2016, 03:21 AM
macropod's Avatar
macropod macropod is offline Dropdownlist-Parsing values to various ContentControls Windows 7 64bit Dropdownlist-Parsing values to various ContentControls Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps you could explain why you're using a userform to solicit data that then gets input into "into the combobox in my document." The code is designed for direct input into a dropdown content control, not for indirect input into a combobox content control. Indirect input means the content control's 'on exit' event never fires, so you'd have to add code to do that as well.

As for the "multiple values separated by the "|" symbol," what are you trying to do with them? The code you're using was written around the idea that all the output would go into a single text content control, with line breaks between the values. If you want the various values separated by the "|" symbol to be output to different text content controls, rather different code would be needed. For example:
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long, StrDetails As String
With ContentControl
  If .Title = "Client" Then
    For i = 1 To .DropdownListEntries.Count
      If .DropdownListEntries(i).Text = .Range.Text Then
        StrDetails = .DropdownListEntries(i).Value
        Exit For
      End If
    Next
    For i = 0 To UBound(Split(StrDetails, "|"))
      ActiveDocument.SelectContentControlsByTitle("Value" & i)(1).Range.Text = Split(StrDetails, "|")(i)
    Next
  End If
End With
End Sub
where the output content controls are titled 'Value0' - 'Value#', where # is the number assigned to the last control to be updated.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-07-2016, 03:43 PM
highrise955 highrise955 is offline Dropdownlist-Parsing values to various ContentControls Windows 10 Dropdownlist-Parsing values to various ContentControls Office 2013
Advanced Beginner
Dropdownlist-Parsing values to various ContentControls
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Perhaps you could explain why you're using a userform to solicit data that then gets input into "into the combobox in my document." The code is designed for direct input into a dropdown content control, not for indirect input into a combobox content control. Indirect input means the content control's 'on exit' event never fires, so you'd have to add code to do that as well.
I apologize in my delay in getting back to you. It was "one of those days".

The reason I am using a userform to get info that I populate into a combobox is simple, if not somewhat convoluted. Knowing the "Drawing Number" (which is the info the userform and the "combobox" focuses on) allows me to fill in about 30% of the rest of the form. However, the layout of the form is locked and I can't move the Drawing Number field to the top. It's currently near the bottom. By having them input it before the document opens ensures that the users won't waste time (and make errors) when inputting the data into the form.

If you are asking why don't I just make the field a text field instead of a combobox it is because I am not skilled enough in VBA and/or XML or whatever method would allow me to store all the values linked to the "Drawing Number".

Here is an example of the data that will be linked to a Drawing Number (each of these values have their own corresponding contentcontrol...

Drawing Number --> Product Description, Rev Level, Material, Job Number, SN's required (which will show as a large check symbol and eventually I would like to make it show a small table where the serial numbers can be entered, otherwise that area would be hidden)

If I was doing this in AHK it would be a breeze, but unfortunately I am bound by ISO standards in the creation of all forms for this company, so I have to make do with what I have (and my current knowledge level at the moment).

I hope this clears up any confusion, or at the very least, not make it worse.

Any suggestions, or pointing me in the right direction, you can offer has been and will continue to be, very appreciated.
Reply With Quote
  #6  
Old 03-07-2016, 04:42 PM
macropod's Avatar
macropod macropod is offline Dropdownlist-Parsing values to various ContentControls Windows 7 64bit Dropdownlist-Parsing values to various ContentControls Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In that case, I don't see any point in using the dropdown content control - you may as well directly populate all areas of the document from a dropdown on the userform. See attached demo.
Attached Files
File Type: docm Userform.docm (29.5 KB, 34 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 03-07-2016, 05:08 PM
highrise955 highrise955 is offline Dropdownlist-Parsing values to various ContentControls Windows 10 Dropdownlist-Parsing values to various ContentControls Office 2013
Advanced Beginner
Dropdownlist-Parsing values to various ContentControls
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
In that case, I don't see any point in using the dropdown content control - you may as well directly populate all areas of the document from a dropdown on the userform. See attached demo.

Now I'm thoroughly confused. I've never used bookmarks so I guess I need to learn those to understand your example better. I understand the basics of your code but I can't seem to see how the code knows where to place the data in the document. I imagine with your example I wouldn't be using contentcontrols to house these values. Though I would still need some for the other data not related to the Drawing Number.

Can I assume I could still use my template with your example?

Thanks for the input. This is definitely a learning experience.
Reply With Quote
  #8  
Old 03-07-2016, 05:35 PM
macropod's Avatar
macropod macropod is offline Dropdownlist-Parsing values to various ContentControls Windows 7 64bit Dropdownlist-Parsing values to various ContentControls Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by highrise955 View Post
I understand the basics of your code but I can't seem to see how the code knows where to place the data in the document.
The document has a series of bookmarks, which you can see via Insert|Bookmark. These are populated by the userform. The userform could just as easily populate a series of content controls.
Quote:
Originally Posted by highrise955 View Post
Can I assume I could still use my template with your example?
Having not seen your template, that's impossible to say for sure, though there's nothing about the code that would necessarily be incompatible with that.

You previously mentioned:
Quote:
SN's required (which will show as a large check symbol and eventually I would like to make it show a small table where the serial numbers can be entered, otherwise that area would be hidden)
Your userform could likewise have another listbox for the user to choose the required SN number and similar - though rather more complex - code could be used to insert the required table and its content.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 03-08-2016, 01:35 AM
highrise955 highrise955 is offline Dropdownlist-Parsing values to various ContentControls Windows 10 Dropdownlist-Parsing values to various ContentControls Office 2013
Advanced Beginner
Dropdownlist-Parsing values to various ContentControls
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
As for the "multiple values separated by the "|" symbol," what are you trying to do with them? The code you're using was written around the idea that all the output would go into a single text content control, with line breaks between the values. If you want the various values separated by the "|" symbol to be output to different text content controls, rather different code would be needed. For example:

Am I correct in assuming that the following code snippet is what would actually populate the various CC's in my form?

Code:
For i = 0 To UBound(Split(StrDetails, "|"))
      ActiveDocument.SelectContentControlsByTitle("Value" & i)(1).Range.Text = Split(StrDetails, "|")(i)
Next
If that is the case would the following hold true...

Code:
For i = 0 to UBound(Split(StrDetails, "|"))
     ActiveDocument.SelectContentControlsByTag("Value" & i)(1).Range.Text = Split(StrDetails, "|")(i)
Next
...where each CC would have the tag "Value0, Value1, Value2..." and so on? Also, can I further assume this code would be placed in the userform and not the actual document?

I really appreciate the time you are taking to assist me in this matter. I'm learning a lot and I sincerely appreciate your continuing effort.
Reply With Quote
  #10  
Old 03-08-2016, 02:03 AM
macropod's Avatar
macropod macropod is offline Dropdownlist-Parsing values to various ContentControls Windows 7 64bit Dropdownlist-Parsing values to various ContentControls Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To use the userform with content controls instead of bookmarks, you might replace:
Code:
      Call UpdateBookmark("Description", "Widget Type A")
      Call UpdateBookmark("Revision", "1.01")
      Call UpdateBookmark("Material", "PVC")
      Call UpdateBookmark("Job_No", "1234")
with:
Code:
      With ActiveDocument
        .SelectContentControlsByTitle("Description")(1).Range.Text = "Widget Type A"
        .SelectContentControlsByTitle("Revision")(1).Range.Text = "1.01"
        .SelectContentControlsByTitle("Material")(1).Range.Text = "PVC"
        .SelectContentControlsByTitle("Job_No")(1).Range.Text = "1234"
      End With
and so on, where the titles are as indicated.

The code you're thinking of using would require all the content to be used for 'StrDetails' to be added programmatically to each of the userform ListBox's entries and, when an item is selected, retrieved from there before it could be used to populate the content controls.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA ppt ComboBox behaivor: 1.OnFocus change value 2. get dropdownlist doesn't disappear after mousec janism22 PowerPoint 2 03-26-2015 12:35 AM
ActiveDocument.ContentControls(ID) not working Tejas.T Word VBA 3 03-09-2015 06:50 PM
Updating grouped ContentControls in Word 2010 MGerhard Word VBA 3 08-04-2014 02:34 AM
Dropdownlist-Parsing values to various ContentControls Parsing 'FullName' column - help needed text to column ScottA Excel Programming 3 05-06-2014 12:49 PM
XML parsing & Object variable not set (Error 91) tinfanide Excel Programming 0 12-29-2011 08:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:19 PM.


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