Results 1 to 5 of 5
  1. #1
    New Lounger Bigshrimp60's Avatar
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    items in listbox appear side by side instead of underneath each other

    Hello

    I have a template with a custom userbox and in it, I have a listbox with a list of 3 names. I want the user to be able to select any 1 or 2 of the 3 names, but never all three, so I set the MultiSelect property of the listbox to "1-fmMultiSelectMulti". Now, how do I get the selection to appear in the document one name under the other instead of side by side. If they select just 1 name, it's good, but that rarely happens.

    I want:
    Name 1
    Name 2

    I am getting:
    Name 1 Name2

    Thanks for helping a grateful newbie!

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    And what is the code you are using to place this listbox content into the document?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger Bigshrimp60's Avatar
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hello
    I figured out how to get my text to line up underneath each other by adding & vbCrLf to the end of each list item, but now I am getting a runtime error 94 Invalid use of null. I don't even have a null.


    Private Sub cmdok_Click()
    With ActiveDocument
    .Bookmarks("type").Range.Text = cbotype.Value
    .Bookmarks("judge").Range.Text = cbojudge.Value
    .Bookmarks("multinames").Range.Text = ListBox1.Value
    End With

    Application.ScreenUpdating = True
    Unload Me

    Selection.GoTo What:=wdGoToBookmark, Name:="start"
    ActiveWindow.View.ShowBookmarks = False
    End Sub



    Private Sub UserForm_Initialize()
    cbojudge.AddItem "Honorable 1"
    cbojudge.AddItem "Honorable 2."
    cbojudge.AddItem "Honorable 3."
    cbojudge.AddItem "Honorable 4"
    cbojudge.AddItem "Honorable 5."
    cbojudge.AddItem "Honorable 6."

    cbotype.ListIndex = 0

    cbotitle.AddItem "OPINION"
    cbotitle.AddItem "ORDER"
    cbotitle.AddItem "DECISION"
    cbotitle.AddItem "DECISION AND ORDER"
    cbotitle.AddItem "OPINION AND ORDER"
    cbotitle.ListIndex = 0


    ListBox1.AddItem "Name 1" & vbCrLf
    ListBox1.AddItem "Name 2" & vbCrLf
    ListBox1.AddItem "Name 3" & vbCrLf
    ListBox1.ListIndex = 0
    End Sub

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Get rid of the vbCrLf from the initialise function and try this instead
    Code:
    Private Sub cmdok_Click()
    Dim i As Integer, sNames as String
    
    With ActiveDocument
    .Bookmarks("type").Range.Text = cbotype.Value
    .Bookmarks("judge").Range.Text = cbojudge.Value
    If ListBox1.ListIndex <> -1 Then
      For i = ListBox1.ListCount - 1 To 0 Step -1
        If ListBox1.Selected(i) = True Then
          sNames = sNames & ListBox1.List(i) & vbCrLf
        End If
      Next i
      sNames = Left(sNames, Len(sNames)-1)
      .Bookmarks("multinames").Range.Text = sNames
    End If
    End With
    
    Application.ScreenUpdating = True
    Unload Me
    
    Selection.GoTo What:=wdGoToBookmark, Name:="start"
    ActiveWindow.View.ShowBookmarks = False
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger Bigshrimp60's Avatar
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Happy! Happy! Joy! Joy! It worked. Thank you so very much.

Posting Permissions

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