Ask Experts Questions for FREE Help !
Ask
    esperanto234's Avatar
    esperanto234 Posts: 5, Reputation: 1
    New Member
     
    #1

    Sep 7, 2009, 09:51 AM
    Listbox Strings to word
    Hi, Im using alistbox to insert names in a word document, I'm using the following code but it only inserts the first ITEM on the list.


    Code:
    Dim strList1 As String
    strList1 = ListBox1.List(ListBox1.ListIndex)
    ActiveDocument.Bookmarks("p91").Range.Text = strList1

    My question is: How can I do to insert ALL items in the listbox in word. I need them to be separated by comas and the last one by "and". Ex:

    ITEM1, ITEM2, ITEM3 and ITEM4.

    ITEM1, ITEM2 and ITEM3.

    ITEM1, ITEM2 and ITEM5.


    Of course, if there's only 1 item I need the "and" to be deleted. Ex:

    ITEM1

    THANK YOU VERY VEERY MUCH!
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #2

    Sep 7, 2009, 10:14 AM

    If you are using a multi-select listbox, then you need to loop through the ItemsSelected collection. When the multi-select property is set to yes, the control itself does not store a value.
    esperanto234's Avatar
    esperanto234 Posts: 5, Reputation: 1
    New Member
     
    #3

    Sep 7, 2009, 11:15 AM
    Quote Originally Posted by ScottGem View Post
    If you are using a multi-select listbox, then you need to loop through the ItemsSelected collection. when the multi-select property is set to yes, the control itself does not store a value.
    Could you please help me with the entire code? I'm using a multi-select listbox.
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #4

    Sep 7, 2009, 11:23 AM

    I don't know the exact code for VB. I can give you an example for Access VBA, but I don't know if that will help. Try googling VB Multi-Select listbox.
    esperanto234's Avatar
    esperanto234 Posts: 5, Reputation: 1
    New Member
     
    #5

    Sep 7, 2009, 11:29 AM
    Quote Originally Posted by ScottGem View Post
    I don't know the exact code for VB. I can give you an example for Access VBA, but I don't know if that will help. Try googling VB Multi-Select listbox.
    Thanks anyway for your help.:D

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Add a time from a TextBox into a ListBox [ 11 Answers ]

I need to add a time from a textbox into a list box with a message after that time. I've tried many different codes all with poor results. Either I can't change the time or when I changed the time it adds every move to the listbox e.g if the time is 10:00 and I want to change it to 2:00 when I...

ListBox and Textbox in VB.NET 2008! [ 4 Answers ]

Hello everyone. Ok so I have in form1 a listbox1 and a textbox1. In the listbox1 I have several items and I want while I type something in the textbox1 it gives me all the similar in listbox1. For Example: I already have in listbox1 the item 'ASKME HELPDESK'. When I type in the textbox1...

Listbox and textbox in vb.net [ 3 Answers ]

Hi there, I wonder if anyone can help. I have a listbox and a textbox. At runtime I already have a list of items in the listbox. When I double click on these items its needs to appear in the textbox. At the moment I have the code that, when I double click on the item in the listbox ONLY one item...

ListBox problem [ 1 Answers ]

If lstSchedule.Items.Contains((0)) = True Then objWriter.WriteLine((0)) End If If lstSchedule.Items.Contains((1)) = True Then objWriter.WriteLine((1)) -----------------------until objWriter.WriteLine((7))--------------------- is this...


View more questions Search