Solved

Word RowSource syntax

Posted on 2014-07-24
4
1,353 Views
Last Modified: 2014-07-25
This should be straight forward, but haven't been able to figure it out.  I have created a Word template that has a form that allows the user to make entries to populate the template.

There are free form text boxes and radio buttons.  I would like to add a simple list box offering a choice between several states.

I cannot for the life of me figure out the RowSource syntax.  I would think it would be something simple like ="Choice1, Choice2, Choice3,...." but this is not working.

I am going to use the value selected in the list box to insert a block of text that will vary depending on the selection.  I have done this successfully based on radio button choices and would like to do the same now with a listbox.
0
Comment
Question by:reportingdude
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40217483
I'm not sure that Word supports bound controls. However, to be clear, are you using ActiveX controls? If so, are they on the document (not recommended), or on a UserForm?
0
 

Author Comment

by:reportingdude
ID: 40217562
Its a UserForm through VBA. I am not sure if the controls are ActiveX controls.  When I hit the toolbar button it has option button, list box, combo box, etc available.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40218702
The controls on a UserForm are all ActiveX controls. They can also be put on documents, but it isn't recommended.

I have researched this a bit more. As far as I can establish, the RowSource property only works if the data is on a Worksheet in the current Workbook. This confines it to Excel.

This Microsoft article http://support.microsoft.com/kb/161598 is headed "How to add data to a ComboBox control or a ListBox control in Excel or Word". The first uses the RowSource and shows how to set it to a worksheet range. The second method uses VBA to set the list to an array, which would, of course work in Word, or any other UserForm host.

A third method is to use AddItem successively
ListBox1.AddItem "Choice1"
ListBox1.AddItem "Choice2"

Open in new window

0
 

Author Closing Comment

by:reportingdude
ID: 40220158
Excellent.  Not sure how I missed finding that link, here are the directions from the link you provided that did the trick:

Methdod 2: How to Use a Visual Basic Macro to Populate a Combo Box or List Box
1.Open a Microsoft Office Application such as Microsoft Excel or Word.
2.Press ALT+F11 to start the Visual Basic Editor.
3.On the Insert menu, click UserForm.
4.Create a ComboBox and a ListBox control on the user form.
5.Right-click the user form and click View Code. The Code window for the user form appears. Click Initialize in the Procedure list (on the right side).

The first and last lines of the subroutine are automatically entered, and the insertion point is automatically placed between these two lines.
6.Type the following code:
      ListBox1.List = Array("One", "Two", "Three", "Four")
      ComboBox1.List = Array("Red", "Green", "Yellow", "Blue")
                                    This code should appear between the lines "Sub UserForm_Initialize()" and "End Sub".
7.On the Run menu, click Run Sub/UserForm to run the user form.
One, Two, Three, and Four appear in the ListBox control; and Red, Green, Yellow, and Blue appear in the ComboBox control.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Upgrading Microsoft WordJ 6 51
VBA code snippets in a Word 2016 document 3 69
copying from excel to word 2 42
Error 5180 Word Cannot open document template 1 28
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now