View Single Post
 
Old 04-13-2019, 03:54 PM
jrooney7 jrooney7 is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Sep 2018
Posts: 23
jrooney7 is on a distinguished road
Default How to populate a userform combobox from a table in the same document

Hello again,

I have uploaded a dotm that has a series of tables. I would like to populate a combobox on a userform from the text in the second column of the first table of the document. This first table will have a different number of rows depending on user entry. The code I have so far is below, and it is recognizing the length (number of rows) in Table 1, as the combobox is growing appropriately, but it is blank (not pulling the text from column 2).

Code:
Private Sub UserForm_Initialize()

    Dim oTable As Table
    Dim i As Long, j As Long, m As Long
    Dim myArray() As Variant
    Dim oData As Range
        Set oTable = ActiveDocument.Tables(1)
        i = oTable.Rows.Count
        ReDim myArray(i, 2)
            For m = 1 To i
                Set oData = oTable.Cell(m, 2).Range
                If oData.Text <> "" Then
                    myArray(m, 2) = oData.Text
                Else
                    myArray(m, 2) = " "
                End If
            Next m
    ItemComboBox.List = myArray

End Sub
Any thoughts as to what I'm doing wrong?

I would also like a textbox on the same userform be filled with text from the fourth column of the first table according to which entry was chosen for the above-mentioned combobox. So if the user selects the entry from the third row, the text from cell(3, 4) would be entered into the textbox. The first table is the Item Submitted png and the result I'm trying to get to is the End Result png.

I have uploaded a sample of the document with entries in the first table and I have entered the above code into the SNR Userform initialize event.
Attached Images
File Type: png Items Submitted table.png (11.9 KB, 24 views)
File Type: png End result.png (40.0 KB, 23 views)
Attached Files
File Type: dotm Firearms Worksheet (for uploading).dotm (446.3 KB, 11 views)

Last edited by jrooney7; 04-13-2019 at 07:34 PM. Reason: Added additional process
Reply With Quote