Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2019, 05:36 AM
jhansrod jhansrod is offline UserForm with Combo Box from data in table within template Windows 10 UserForm with Combo Box from data in table within template Office 2016
Novice
UserForm with Combo Box from data in table within template
 
Join Date: Jun 2019
Posts: 16
jhansrod is on a distinguished road
Default UserForm with Combo Box from data in table within template

Good day



Firstly, thank you to Graham Mayor for his sharing of tips.

I have been learning from www.gmayor.com/Userform.htm and think that this could be the solution to my current challenge.

The challenge is that I need to create a document based on input from users. I have tried doing this with Acrobat DC forms, however this is proving to be a challenge due to Java Scripting.

I believe that using MS Word and VBA, this will be much better.

Based on the tutorial by Graham, I would like to know if it is possible to hold the data for a Combo Box within the same document which I can then protect and have only the user form executed. If possible use the values in the Content Control.

This will avoid issues with having to manage multiple files.

Thank you
J
Reply With Quote
  #2  
Old 06-12-2019, 08:58 AM
gmaxey gmaxey is offline UserForm with Combo Box from data in table within template Windows 10 UserForm with Combo Box from data in table within template 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

The attached will show you how you can store table data in a document customXML part then use it to populate your CC dropdown.
Attached Files
File Type: dotm Store external table data in CustomXMLPart.dotm (55.0 KB, 23 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-12-2019, 08:31 PM
gmayor's Avatar
gmayor gmayor is offline UserForm with Combo Box from data in table within template Windows 10 UserForm with Combo Box from data in table within template Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

While Greg's suggestion may do what you want, without knowing what the data is that you want to store in the userform it is difficult to suggest the best approach. You could for example populate the combo box from the code that calls the userform without the need for another document or table.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 06-12-2019, 09:02 PM
jhansrod jhansrod is offline UserForm with Combo Box from data in table within template Windows 10 UserForm with Combo Box from data in table within template Office 2016
Novice
UserForm with Combo Box from data in table within template
 
Join Date: Jun 2019
Posts: 16
jhansrod is on a distinguished road
Default

Thank you both.
The option to be able to update the table is great however as the options will be static, the option to populate from user form code is the one best suited for me.

Could you share a sample of the code that could do this.

Thank you
Reply With Quote
  #5  
Old 06-12-2019, 11:13 PM
gmayor's Avatar
gmayor gmayor is offline UserForm with Combo Box from data in table within template Windows 10 UserForm with Combo Box from data in table within template Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

At its simplest you would just add items to the combobox e.g.

Code:
Private Sub UserForm_Initialize()
    With ComboBox1
        .AddItem "Select an Item"
        .AddItem "This is the first item"
        .AddItem "This is the second item"
        .AddItem "This is the third item"
        .ListIndex = 0
    End With
End Sub
or you could use an array e.g.
Code:
Private Sub UserForm_Initialize()
Dim vList As Variant
    vList = Array("Select an Item", "This is the first item", "This is the second item", "This is the third item")
    With ComboBox1
        .List = vList
        .ListIndex = 0
    End With
End Sub
or a combination of the two e.g.
Code:
Private Sub UserForm_Initialize()
Dim vList(3) As Variant
    vList(0) = "Select an Item"
    vList(1) = "This is the first item"
    vList(2) = "This is the second item"
    vList(3) = "This is the third item"

    With ComboBox1
        .List = vList
        .ListIndex = 0
    End With
End Sub
You would populate the appropriate part of the document, ideally using a content control, with the value from the combobox.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #6  
Old 06-13-2019, 07:05 AM
jhansrod jhansrod is offline UserForm with Combo Box from data in table within template Windows 10 UserForm with Combo Box from data in table within template Office 2016
Novice
UserForm with Combo Box from data in table within template
 
Join Date: Jun 2019
Posts: 16
jhansrod is on a distinguished road
Default

Hi Graham

That works great however on my inquest to have a rounded view, how can I do the same if it is a Content Control ComboBox.

Thanks
J
Reply With Quote
  #7  
Old 06-13-2019, 09:02 AM
gmaxey gmaxey is offline UserForm with Combo Box from data in table within template Windows 10 UserForm with Combo Box from data in table within template 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

In the ThisDocument module:

Code:
Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim lngIndex As Long

  Select Case ContentControl.Title
    Case "Demo"
      With ContentControl.DropdownListEntries
        For lngIndex = .Count To 2 Step -1
          .Item(lngIndex).Delete
        Next
        .Add "Apples", "Apples"
        .Add "Blueberries", "Blueberries"
        .Add "Cherries", "Cherries"
      End With
  End Select
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
combo box, user forms

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Letter Template /w combo box list etruz Word 4 10-31-2018 05:16 AM
Copy excel userform data to a word template Farnkf1970 Excel Programming 1 10-31-2017 01:35 AM
Pasting a table with combo boxes to a new document looses the combo box bobsut@enviro-consult.com Word 1 01-03-2017 01:29 PM
userform to enter multiple lines of data in template callasabra Word VBA 0 06-27-2014 05:29 PM
Forms - Combo Box Linking data tomkat Word 1 04-23-2010 06:28 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:46 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