Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Aug 2001
    Location
    Hampshire, England
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combo box filling blues (Wd97 (SR2))

    Can anyone help with this one?
    I

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Combo box filling blues (Wd97 (SR2))

    Is it okay to alphabetize the project names? If so, it would be a lot easier to check for duplicates. Something along the following lines:

    <pre>Private Sub UserForm_Initialize()
    Dim strArray() As String, intRows As Integer, intCounter As Integer
    'count rows in the first table in the active document and size an array
    intRows = ActiveDocument.Tables(1).Range.Information(wdMaxim umNumberOfRows)
    ReDim strArray(intRows - 1)
    'fill the array with the data from the table cells (includes trailing control characters)
    For intCounter = 0 To intRows - 1
    strArray(intCounter) = ActiveDocument.Tables(1).Cell(intCounter + 1, 4).Range.Text
    Next
    'sort array alphabetically/ascending
    WordBasic.SortArray strArray()
    'add nonduplicate items to listbox, discarding trailing control characters
    For intCounter = 0 To UBound(strArray)
    If intCounter = 0 Then
    Me.ListBox1.AddItem Left(strArray(intCounter), Len(strArray(intCounter)) - 2)
    ElseIf strArray(intCounter) <> strArray(intCounter - 1) Then
    Me.ListBox1.AddItem Left(strArray(intCounter), Len(strArray(intCounter)) - 2)
    End If
    Next
    End Sub</pre>


  3. #3
    Star Lounger
    Join Date
    Aug 2001
    Location
    Hampshire, England
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combo box filling blues (Wd97 (SR2))

    Yes, it's okay to alphabetize the entries (probably preferable actually, now I think about it). Looks good from a quick test: I'll stick it into the actual document over the weekend.

    Thanks for this code and the quick reply!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •