I developed a user form in Word using a list box, which
populated great from a 3 column table. Code follows.

Now boss wants a combo box not a list box, and I can't get
the 3 columns to load. I want the first column to be the
options to choose from in the combo box (list of names)
and then populate two text boxes (textbox1 and textbox2)
with the information from columns 2 and 3 going with the
name selected from column one. I just can't make it work,
can anyone help.

Here is the listbox code that does work:

Private Sub CommandButton2_Click()
Dim Msg, Style 'set dim for message box when Exit is
pressed

Msg = "Please wait while program shuts down" ' define
message
Style = vbYesOk + vbCritical + vbDefaultButton2 '
define message response buttons
Response = MsgBox(Msg, Style) ' Display message

If True Then Unload UserForm1
Application.DisplayAlerts = False

Word.Application.Quit

End Sub

Private Sub UserForm_Initialize()


Dim MyArray() As String
RowCount = ActiveDocument.Tables(1).Rows.Count
RowCount = ActiveDocument.Tables(1).Rows.Count
ColCount = ActiveDocument.Tables(1).Columns.Count
ReDim MyArray(RowCount - 1, ColCount - 1)
For i = 1 To RowCount
For j = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(1).Cell(i, j)
'Remove the paragraph and end-of-cell markers
'as we lod the array

MyArray(i - 1, j - 1) = Left(Celldata, Len
(Celldata) - 2)
Next
Next
ListBox1.ColumnCount = ColCount
ListBox1.List() = MyArray


Dim MyArrayExternal() As String
RowCount = ActiveDocument.Tables(2).Rows.Count
RowCount = ActiveDocument.Tables(2).Rows.Count
ColCount = ActiveDocument.Tables(2).Columns.Count
ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
For m = 1 To RowCount
For n = 1 To ColCount
'Select each cell in the table
Celldata = ActiveDocument.Tables(2).Cell(m, n)
'Remove the paragraph and end-of-cell markers
'as we load the array
MyArrayExternal(m - 1, n - 1) = Left(Celldata,
Len(Celldata) - 2)
Next
Next
ListBox2.ColumnCount = ColCount
ListBox2.List() = MyArrayExternal

End Sub

Private Sub ListBox1_Click()

For x = 0 To ListBox1.ListCount

If ListBox1.Selected(x) = True Then
MsgBox "Name:" & " " &
ListBox1.List(x) & (Chr(13)) & "Office Symbol:" &
ListSeparator & " " & ListBox1.List(x, 1) & (Chr
(13)) & "Project(s):" & ListSeparator & " " &
ListBox1.List(x, 2)
End If
Next x
End Sub

Private Sub ListBox2_Click()

For x = 0 To ListBox2.ListCount

If ListBox2.Selected(x) = True Then
MsgBox "Name:" & " " &
ListBox2.List(x) & (Chr(13)) & "Office Symbol:" &
ListSeparator & " " & ListBox2.List(x, 1) & (Chr
(13)) & "Project(s):" & ListSeparator & " " &
ListBox2.List(x, 2)
End If
Next x
End Sub


I've tried replacing ListBox1.Selected(x) with a
MatchFound for the ComboBox, but it wouldn't work. Where
am I missing the boat.

Re: Combo Box List Problems by Word

Word
Thu Dec 11 16:16:37 CST 2003

G'day "Pam" <anonymous@discussions.microsoft.com>,

when the combo _Change event fires, examine the list value and
populate the two list boxes accordingly.


"Pam" <anonymous@discussions.microsoft.com> was spinning this yarn:

>I developed a user form in Word using a list box, which
>populated great from a 3 column table. Code follows.
>
>Now boss wants a combo box not a list box, and I can't get
>the 3 columns to load. I want the first column to be the
>options to choose from in the combo box (list of names)
>and then populate two text boxes (textbox1 and textbox2)
>with the information from columns 2 and 3 going with the
>name selected from column one. I just can't make it work,
>can anyone help.
>
>Here is the listbox code that does work:
>
>Private Sub CommandButton2_Click()
> Dim Msg, Style 'set dim for message box when Exit is
>pressed
>
> Msg = "Please wait while program shuts down" ' define
>message
> Style = vbYesOk + vbCritical + vbDefaultButton2 '
>define message response buttons
> Response = MsgBox(Msg, Style) ' Display message
>
> If True Then Unload UserForm1
> Application.DisplayAlerts = False
>
> Word.Application.Quit
>
>End Sub
>
>Private Sub UserForm_Initialize()
>
>
> Dim MyArray() As String
> RowCount = ActiveDocument.Tables(1).Rows.Count
> RowCount = ActiveDocument.Tables(1).Rows.Count
> ColCount = ActiveDocument.Tables(1).Columns.Count
> ReDim MyArray(RowCount - 1, ColCount - 1)
> For i = 1 To RowCount
> For j = 1 To ColCount
> 'Select each cell in the table
> Celldata = ActiveDocument.Tables(1).Cell(i, j)
> 'Remove the paragraph and end-of-cell markers
> 'as we lod the array
>
> MyArray(i - 1, j - 1) = Left(Celldata, Len
>(Celldata) - 2)
> Next
> Next
> ListBox1.ColumnCount = ColCount
> ListBox1.List() = MyArray
>
>
> Dim MyArrayExternal() As String
> RowCount = ActiveDocument.Tables(2).Rows.Count
> RowCount = ActiveDocument.Tables(2).Rows.Count
> ColCount = ActiveDocument.Tables(2).Columns.Count
> ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
> For m = 1 To RowCount
> For n = 1 To ColCount
> 'Select each cell in the table
> Celldata = ActiveDocument.Tables(2).Cell(m, n)
> 'Remove the paragraph and end-of-cell markers
> 'as we load the array
> MyArrayExternal(m - 1, n - 1) = Left(Celldata,
>Len(Celldata) - 2)
> Next
> Next
> ListBox2.ColumnCount = ColCount
> ListBox2.List() = MyArrayExternal
>
>End Sub
>
>Private Sub ListBox1_Click()
>
> For x = 0 To ListBox1.ListCount
>
> If ListBox1.Selected(x) = True Then
> MsgBox "Name:" & " " &
>ListBox1.List(x) & (Chr(13)) & "Office Symbol:" &
>ListSeparator & " " & ListBox1.List(x, 1) & (Chr
>(13)) & "Project(s):" & ListSeparator & " " &
>ListBox1.List(x, 2)
> End If
> Next x
>End Sub
>
>Private Sub ListBox2_Click()
>
> For x = 0 To ListBox2.ListCount
>
> If ListBox2.Selected(x) = True Then
> MsgBox "Name:" & " " &
>ListBox2.List(x) & (Chr(13)) & "Office Symbol:" &
>ListSeparator & " " & ListBox2.List(x, 1) & (Chr
>(13)) & "Project(s):" & ListSeparator & " " &
>ListBox2.List(x, 2)
> End If
> Next x
>End Sub
>
>
>I've tried replacing ListBox1.Selected(x) with a
>MatchFound for the ComboBox, but it wouldn't work. Where
>am I missing the boat.
>

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.

Re: Combo Box List Problems by anonymous

anonymous
Fri Dec 12 07:42:23 CST 2003

Still not sure how that would work?
>-----Original Message-----
>G'day "Pam" <anonymous@discussions.microsoft.com>,
>
>when the combo _Change event fires, examine the list
value and
>populate the two list boxes accordingly.
>
>
> "Pam" <anonymous@discussions.microsoft.com> was spinning
this yarn:
>
>>I developed a user form in Word using a list box, which
>>populated great from a 3 column table. Code follows.
>>
>>Now boss wants a combo box not a list box, and I can't
get
>>the 3 columns to load. I want the first column to be
the
>>options to choose from in the combo box (list of names)
>>and then populate two text boxes (textbox1 and textbox2)
>>with the information from columns 2 and 3 going with the
>>name selected from column one. I just can't make it
work,
>>can anyone help.
>>
>>Here is the listbox code that does work:
>>
>>Private Sub CommandButton2_Click()
>> Dim Msg, Style 'set dim for message box when Exit is
>>pressed
>>
>> Msg = "Please wait while program shuts down" '
define
>>message
>> Style = vbYesOk + vbCritical + vbDefaultButton2 '
>>define message response buttons
>> Response = MsgBox(Msg, Style) ' Display message
>>
>> If True Then Unload UserForm1
>> Application.DisplayAlerts = False
>>
>> Word.Application.Quit
>>
>>End Sub
>>
>>Private Sub UserForm_Initialize()
>>
>>
>> Dim MyArray() As String
>> RowCount = ActiveDocument.Tables(1).Rows.Count
>> RowCount = ActiveDocument.Tables(1).Rows.Count
>> ColCount = ActiveDocument.Tables(1).Columns.Count
>> ReDim MyArray(RowCount - 1, ColCount - 1)
>> For i = 1 To RowCount
>> For j = 1 To ColCount
>> 'Select each cell in the table
>> Celldata = ActiveDocument.Tables(1).Cell(i,
j)
>> 'Remove the paragraph and end-of-cell markers
>> 'as we lod the array
>>
>> MyArray(i - 1, j - 1) = Left(Celldata, Len
>>(Celldata) - 2)
>> Next
>> Next
>> ListBox1.ColumnCount = ColCount
>> ListBox1.List() = MyArray
>>
>>
>> Dim MyArrayExternal() As String
>> RowCount = ActiveDocument.Tables(2).Rows.Count
>> RowCount = ActiveDocument.Tables(2).Rows.Count
>> ColCount = ActiveDocument.Tables(2).Columns.Count
>> ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
>> For m = 1 To RowCount
>> For n = 1 To ColCount
>> 'Select each cell in the table
>> Celldata = ActiveDocument.Tables(2).Cell(m,
n)
>> 'Remove the paragraph and end-of-cell markers
>> 'as we load the array
>> MyArrayExternal(m - 1, n - 1) = Left(Celldata,
>>Len(Celldata) - 2)
>> Next
>> Next
>> ListBox2.ColumnCount = ColCount
>> ListBox2.List() = MyArrayExternal
>>
>>End Sub
>>
>>Private Sub ListBox1_Click()
>>
>> For x = 0 To ListBox1.ListCount
>>
>> If ListBox1.Selected(x) = True Then
>> MsgBox "Name:" & " " &
>>ListBox1.List(x) & (Chr(13)) & "Office Symbol:" &
>>ListSeparator & " " & ListBox1.List(x, 1) & (Chr
>>(13)) & "Project(s):" & ListSeparator & " "
&
>>ListBox1.List(x, 2)
>> End If
>> Next x
>>End Sub
>>
>>Private Sub ListBox2_Click()
>>
>> For x = 0 To ListBox2.ListCount
>>
>> If ListBox2.Selected(x) = True Then
>> MsgBox "Name:" & " " &
>>ListBox2.List(x) & (Chr(13)) & "Office Symbol:" &
>>ListSeparator & " " & ListBox2.List(x, 1) & (Chr
>>(13)) & "Project(s):" & ListSeparator & " "
&
>>ListBox2.List(x, 2)
>> End If
>> Next x
>>End Sub
>>
>>
>>I've tried replacing ListBox1.Selected(x) with a
>>MatchFound for the ComboBox, but it wouldn't work.
Where
>>am I missing the boat.
>>
>
>Steve Hudson
>
>Word Heretic, Sydney, Australia
>Tricky stuff with Word or words for you.
>wordheretic.com
>
>If my answers r 2 terse, ask again or hassle an MVP,
>at least they get recognition for it then.
>Lengthy replies offlist require payment.
>.
>

Re: Combo Box List Problems by Word

Word
Fri Dec 12 15:38:33 CST 2003

G'day <anonymous@discussions.microsoft.com>,

We define a 3d array. Col 1 is for combo, 2 is for textbox1 and 3 is
for textbox2

We stuff our values into the array - easy enough.

We read back the array,1 to fill combo

Combo change event uses .listindex to get the offset into the array to
drag up values for textbox1 and textbox2

If the user needs to change textbox1 and textbox2 it gets trickier.

We define a private to the form var called Changing of type Boolean

Private Changing as Boolean

When we go to pop the textboxes from our change event, we set
Changing=True. After setting the textboxes, we set change-false again.

The textboxes change events then look like this:

If Not Changing then
'doo de doo everything you need in here
end if



<anonymous@discussions.microsoft.com> was spinning this yarn:

>Still not sure how that would work?
>>-----Original Message-----
>>G'day "Pam" <anonymous@discussions.microsoft.com>,
>>
>>when the combo _Change event fires, examine the list
>value and
>>populate the two list boxes accordingly.
>>
>>
>> "Pam" <anonymous@discussions.microsoft.com> was spinning
>this yarn:
>>
>>>I developed a user form in Word using a list box, which
>>>populated great from a 3 column table. Code follows.
>>>
>>>Now boss wants a combo box not a list box, and I can't
>get
>>>the 3 columns to load. I want the first column to be
>the
>>>options to choose from in the combo box (list of names)
>>>and then populate two text boxes (textbox1 and textbox2)
>>>with the information from columns 2 and 3 going with the
>>>name selected from column one. I just can't make it
>work,
>>>can anyone help.
>>>
>>>Here is the listbox code that does work:
>>>
>>>Private Sub CommandButton2_Click()
>>> Dim Msg, Style 'set dim for message box when Exit is
>>>pressed
>>>
>>> Msg = "Please wait while program shuts down" '
>define
>>>message
>>> Style = vbYesOk + vbCritical + vbDefaultButton2 '
>>>define message response buttons
>>> Response = MsgBox(Msg, Style) ' Display message
>>>
>>> If True Then Unload UserForm1
>>> Application.DisplayAlerts = False
>>>
>>> Word.Application.Quit
>>>
>>>End Sub
>>>
>>>Private Sub UserForm_Initialize()
>>>
>>>
>>> Dim MyArray() As String
>>> RowCount = ActiveDocument.Tables(1).Rows.Count
>>> RowCount = ActiveDocument.Tables(1).Rows.Count
>>> ColCount = ActiveDocument.Tables(1).Columns.Count
>>> ReDim MyArray(RowCount - 1, ColCount - 1)
>>> For i = 1 To RowCount
>>> For j = 1 To ColCount
>>> 'Select each cell in the table
>>> Celldata = ActiveDocument.Tables(1).Cell(i,
>j)
>>> 'Remove the paragraph and end-of-cell markers
>>> 'as we lod the array
>>>
>>> MyArray(i - 1, j - 1) = Left(Celldata, Len
>>>(Celldata) - 2)
>>> Next
>>> Next
>>> ListBox1.ColumnCount = ColCount
>>> ListBox1.List() = MyArray
>>>
>>>
>>> Dim MyArrayExternal() As String
>>> RowCount = ActiveDocument.Tables(2).Rows.Count
>>> RowCount = ActiveDocument.Tables(2).Rows.Count
>>> ColCount = ActiveDocument.Tables(2).Columns.Count
>>> ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
>>> For m = 1 To RowCount
>>> For n = 1 To ColCount
>>> 'Select each cell in the table
>>> Celldata = ActiveDocument.Tables(2).Cell(m,
>n)
>>> 'Remove the paragraph and end-of-cell markers
>>> 'as we load the array
>>> MyArrayExternal(m - 1, n - 1) = Left(Celldata,
>>>Len(Celldata) - 2)
>>> Next
>>> Next
>>> ListBox2.ColumnCount = ColCount
>>> ListBox2.List() = MyArrayExternal
>>>
>>>End Sub
>>>
>>>Private Sub ListBox1_Click()
>>>
>>> For x = 0 To ListBox1.ListCount
>>>
>>> If ListBox1.Selected(x) = True Then
>>> MsgBox "Name:" & " " &
>>>ListBox1.List(x) & (Chr(13)) & "Office Symbol:" &
>>>ListSeparator & " " & ListBox1.List(x, 1) & (Chr
>>>(13)) & "Project(s):" & ListSeparator & " "
>&
>>>ListBox1.List(x, 2)
>>> End If
>>> Next x
>>>End Sub
>>>
>>>Private Sub ListBox2_Click()
>>>
>>> For x = 0 To ListBox2.ListCount
>>>
>>> If ListBox2.Selected(x) = True Then
>>> MsgBox "Name:" & " " &
>>>ListBox2.List(x) & (Chr(13)) & "Office Symbol:" &
>>>ListSeparator & " " & ListBox2.List(x, 1) & (Chr
>>>(13)) & "Project(s):" & ListSeparator & " "
>&
>>>ListBox2.List(x, 2)
>>> End If
>>> Next x
>>>End Sub
>>>
>>>
>>>I've tried replacing ListBox1.Selected(x) with a
>>>MatchFound for the ComboBox, but it wouldn't work.
>Where
>>>am I missing the boat.
>>>
>>
>>Steve Hudson
>>
>>Word Heretic, Sydney, Australia
>>Tricky stuff with Word or words for you.
>>wordheretic.com
>>
>>If my answers r 2 terse, ask again or hassle an MVP,
>>at least they get recognition for it then.
>>Lengthy replies offlist require payment.
>>.
>>

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.

Re: Combo Box List Problems by Pam

Pam
Mon Dec 15 07:26:55 CST 2003

Thanks, I will try it with the 3d array.
>-----Original Message-----
>G'day <anonymous@discussions.microsoft.com>,
>
>We define a 3d array. Col 1 is for combo, 2 is for
textbox1 and 3 is
>for textbox2
>
>We stuff our values into the array - easy enough.
>
>We read back the array,1 to fill combo
>
>Combo change event uses .listindex to get the offset into
the array to
>drag up values for textbox1 and textbox2
>
>If the user needs to change textbox1 and textbox2 it gets
trickier.
>
>We define a private to the form var called Changing of
type Boolean
>
>Private Changing as Boolean
>
>When we go to pop the textboxes from our change event, we
set
>Changing=True. After setting the textboxes, we set change-
false again.
>
>The textboxes change events then look like this:
>
>If Not Changing then
> 'doo de doo everything you need in here
>end if
>
>
>
> <anonymous@discussions.microsoft.com> was spinning this
yarn:
>
>>Still not sure how that would work?
>>>-----Original Message-----
>>>G'day "Pam" <anonymous@discussions.microsoft.com>,
>>>
>>>when the combo _Change event fires, examine the list
>>value and
>>>populate the two list boxes accordingly.
>>>
>>>
>>> "Pam" <anonymous@discussions.microsoft.com> was
spinning
>>this yarn:
>>>
>>>>I developed a user form in Word using a list box,
which
>>>>populated great from a 3 column table. Code follows.
>>>>
>>>>Now boss wants a combo box not a list box, and I can't
>>get
>>>>the 3 columns to load. I want the first column to be
>>the
>>>>options to choose from in the combo box (list of
names)
>>>>and then populate two text boxes (textbox1 and
textbox2)
>>>>with the information from columns 2 and 3 going with
the
>>>>name selected from column one. I just can't make it
>>work,
>>>>can anyone help.
>>>>
>>>>Here is the listbox code that does work:
>>>>
>>>>Private Sub CommandButton2_Click()
>>>> Dim Msg, Style 'set dim for message box when Exit
is
>>>>pressed
>>>>
>>>> Msg = "Please wait while program shuts down" '
>>define
>>>>message
>>>> Style = vbYesOk + vbCritical + vbDefaultButton2 '
>>>>define message response buttons
>>>> Response = MsgBox(Msg, Style) ' Display message
>>>>
>>>> If True Then Unload UserForm1
>>>> Application.DisplayAlerts = False
>>>>
>>>> Word.Application.Quit
>>>>
>>>>End Sub
>>>>
>>>>Private Sub UserForm_Initialize()
>>>>
>>>>
>>>> Dim MyArray() As String
>>>> RowCount = ActiveDocument.Tables(1).Rows.Count
>>>> RowCount = ActiveDocument.Tables(1).Rows.Count
>>>> ColCount = ActiveDocument.Tables
(1).Columns.Count
>>>> ReDim MyArray(RowCount - 1, ColCount - 1)
>>>> For i = 1 To RowCount
>>>> For j = 1 To ColCount
>>>> 'Select each cell in the table
>>>> Celldata = ActiveDocument.Tables(1).Cell
(i,
>>j)
>>>> 'Remove the paragraph and end-of-cell markers
>>>> 'as we lod the array
>>>>
>>>> MyArray(i - 1, j - 1) = Left(Celldata, Len
>>>>(Celldata) - 2)
>>>> Next
>>>> Next
>>>> ListBox1.ColumnCount = ColCount
>>>> ListBox1.List() = MyArray
>>>>
>>>>
>>>> Dim MyArrayExternal() As String
>>>> RowCount = ActiveDocument.Tables(2).Rows.Count
>>>> RowCount = ActiveDocument.Tables(2).Rows.Count
>>>> ColCount = ActiveDocument.Tables
(2).Columns.Count
>>>> ReDim MyArrayExternal(RowCount - 1, ColCount - 1)
>>>> For m = 1 To RowCount
>>>> For n = 1 To ColCount
>>>> 'Select each cell in the table
>>>> Celldata = ActiveDocument.Tables(2).Cell
(m,
>>n)
>>>> 'Remove the paragraph and end-of-cell markers
>>>> 'as we load the array
>>>> MyArrayExternal(m - 1, n - 1) = Left
(Celldata,
>>>>Len(Celldata) - 2)
>>>> Next
>>>> Next
>>>> ListBox2.ColumnCount = ColCount
>>>> ListBox2.List() = MyArrayExternal
>>>>
>>>>End Sub
>>>>
>>>>Private Sub ListBox1_Click()
>>>>
>>>> For x = 0 To ListBox1.ListCount
>>>>
>>>> If ListBox1.Selected(x) = True Then
>>>> MsgBox "Name:" & " " &
>>>>ListBox1.List(x) & (Chr(13)) & "Office Symbol:" &
>>>>ListSeparator & " " & ListBox1.List(x, 1) & (Chr
>>>>(13)) & "Project(s):" & ListSeparator
& " "
>>&
>>>>ListBox1.List(x, 2)
>>>> End If
>>>> Next x
>>>>End Sub
>>>>
>>>>Private Sub ListBox2_Click()
>>>>
>>>> For x = 0 To ListBox2.ListCount
>>>>
>>>> If ListBox2.Selected(x) = True Then
>>>> MsgBox "Name:" & " " &
>>>>ListBox2.List(x) & (Chr(13)) & "Office Symbol:" &
>>>>ListSeparator & " " & ListBox2.List(x, 1) & (Chr
>>>>(13)) & "Project(s):" & ListSeparator
& " "
>>&
>>>>ListBox2.List(x, 2)
>>>> End If
>>>> Next x
>>>>End Sub
>>>>
>>>>
>>>>I've tried replacing ListBox1.Selected(x) with a
>>>>MatchFound for the ComboBox, but it wouldn't work.
>>Where
>>>>am I missing the boat.
>>>>
>>>
>>>Steve Hudson
>>>
>>>Word Heretic, Sydney, Australia
>>>Tricky stuff with Word or words for you.
>>>wordheretic.com
>>>
>>>If my answers r 2 terse, ask again or hassle an MVP,
>>>at least they get recognition for it then.
>>>Lengthy replies offlist require payment.
>>>.
>>>
>
>Steve Hudson
>
>Word Heretic, Sydney, Australia
>Tricky stuff with Word or words for you.
>wordheretic.com
>
>If my answers r 2 terse, ask again or hassle an MVP,
>at least they get recognition for it then.
>Lengthy replies offlist require payment.
>.
>