P
Pam
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.
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.