Microsoft KB Archive/194027

= WD98: How to Create a Combo Box Containing More Than 25 Items =

Article ID: 194027

Article Last Modified on 6/17/2005

-

APPLIES TO


 * Microsoft Word 98 for Macintosh

-



This article was previously published under Q194027





SUMMARY
This article describes how to create and use a user form combo box as an entry macro for a text form field. This macro can be used as a workaround for the 25-item limitation in drop-down form fields.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

In your template, follow these steps:

NOTE: To close a window (for example, a code window or the properties window), click the box in the upper-left corner of the window.

Create the UserForm Combo Box
To create the userform combo box, follow these steps:

 On the Tools menu, point to Macro, and then click Visual Basic Editor. In the Project Window, select your TemplateProject.

NOTE: If the Project window does not show, click Project Explorer on the View menu.  On the Insert menu, click UserForm. A new user form and the Controls Toolbox show. CONTROL+Click the user form and then click View Code on the shortcut menu. Add the following code: Private Sub frmcombo_Initialize ComboBox1.ColumnCount = 1 ' Load MyArray MyArray(0) = "Zero" MyArray(1) = "One" MyArray(2) = "Two" MyArray(3) = "Three" ' Load data into ComboBox ComboBox1.List = MyArray ComboBox1.Value = MyArray(1) End Sub and then close the code window.

NOTE: MyArray can contain as many (or few) items as you need. The array is not limited to 25 items like the drop-down form field.

CONTROL+Click the user form and then click Properties on the shortcut menu. On the Alphabetic tab, rename (Name) to frmcombo and then rename Caption to Microsoft Word. Close the UserForm Properties window.   On the Controls tab of the toolbox, select ComboBox and place it on your user form. CONTROL+Click the ComboBox control and then click View Code on the shortcut menu. Change the ComboBox code to: Private Sub ComboBox1_Change ActiveDocument.FormFields("Text1").Result = ComboBox1.Value End Sub and then close the code window.

NOTE: Text1 is the bookmark name of the text form field that you insert into your template in step 2 of the "Create the Text Form Field" procedure of this article.   On the Controls tab of the toolbox, select the CommandButton and place it on your user form as a Close button. CONTROL+Click the command button and then click View Code on the shortcut menu. Change the command button code to the following: Private Sub Cmdclose_Click Unload Me End Sub and then close the code window. CONTROL+Click the command button and click Properties on the shortcut menu. On the Alphabetic tab, rename (Name) to Cmdclose and then rename Caption to Close. Close the CommandButton Properties window. 

The user form combo box is now complete. Proceed to the "Create the Entry Macro" procedure to create the entry macro.

Create the Entry Macro
To create the entry macro, follow these steps:  In the Project Window, select your TemplateProject.</li> On the Insert menu, click Module. A blank module code sheet will be displayed.</li>  Type in the following code: Dim MyArray(3)

Sub gocombobox frmcombo.Show End Sub NOTE: Make sure the DIM MyArray statement contains the highest array number of the items contained in your array (not the total number of array items) from step 3 of the "Create the User Form Combo Box" procedure listed in this article. For example, if you add a fifth item (MyArray(4) = "Four") to the example array in step 3 of the "Create the User Form Combo Box" procedure, make sure you change the DIM MyArray(3) statement to DIM MyArray(4). </li></ol>

The entry macro is now complete. On the File menu, click Close and Return to Microsoft Word.

Create the Text Form Field
To create the text form field, follow these steps:
 * 1) In your template, on the View menu, point to Toolbars, and then click Forms.
 * 2) Position your insertion point where you want the result of the drop down list inserted. On the Forms toolbar, click Text Form Field (the first button on the left). The text form field will be inserted into your template as gray shading.

NOTE: If you see the {FORMTEXT} field, press OPTION+F9 to turn the field codes off.
 * 1) CONTROL+Click the text form field and then click Properties on the shortcut menu.
 * 2) In the Text Form Field Options dialog box, under the Run macro on section, click the down arrow in the Entry box and select the gocombobox macro.

NOTE: Make sure the Bookmark name of your Text Form Field is the same as the one you specified in step 4 of the "Create the User Form Combo Box" procedure earlier in this article.
 * 1) On the Forms toolbar, click Protect Form.
 * 2) Save and close your template.

To use your template, click New on the File menu. Select your template and then click OK. A new document based on your template will be shown. The user form containing the ComboBox with your items will be displayed when you tab into the text form Field.

Additional query words: vba

Keywords: kbhowto kbfield KB194027

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.