WD97: How to Create a Combo Box Containing More Than 25 ItemsID: Q194026
|
This article describes how to create and use a UserForm 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.
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals 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 needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
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
End Sub
and then close the code window.
Private Sub ComboBox1_Change()
ActiveDocument.FormFields("Text1").Result = ComboBox1.Value
End Sub
and then close the code window.
Private Sub Cmdclose_Click()
End
End Sub
and then close the code window. Right-click the CommandButton 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.
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 earlier 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).
Additional query words: vba
Keywords : kbdta kbdtacode kbmacroexample kbwordvba kbfield word97 kbform
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 14, 1999