Reference ComboBox item to fill ListBox 
Author Message
 Reference ComboBox item to fill ListBox

I am currently working on a multi-page userform which contains a
ComboBox and a ListBox on one of the pages. I would like the user to
be able to select an item in the ComboBox and then key a short list of
items into the ListBox. The intention is that the contents of the
ListBox will be then transferred to a bookmark in a Word document that
corresponds with the ComboBox item.

I've spent many hours trying (unsuccessfully) to do this.

The process could be described as:

If ComboBox item = XXX Then
        Type list into ListBox Then
                Send ListBox items to bookmark in document.

Next ComboBox item .....
        Next list .....

The ListBox items should appear in the document under headings with
the same names as the ComboBox items. The process will be repeated for
each of the items in the ComboBox.

Any help in putting together the code to achieve this would be much
appreciated. I'm very much a newbie at VBA programming.

Regards

Pat W



Fri, 12 Nov 2004 09:48:58 GMT  
 Reference ComboBox item to fill ListBox
Hi Pat,

Quote:
> I would like the user to
> be able to select an item in the ComboBox and then key a short list of
> items into the ListBox.

Technically, the user can't simply type a list of items into a list box.
He'd have to type them in a text box, and your code would have to add
them to a list box. Is this really what you need? Or would a multi-line
text box (that the user can use to create a list) be more appropriate?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)



Fri, 12 Nov 2004 16:28:50 GMT  
 Reference ComboBox item to fill ListBox
Pat

Quote:
> If ComboBox item = XXX Then
> Type list into ListBox Then
> Send ListBox items to bookmark in document.

This is a simple solution with two buttons. One adds items to the listbox
the other adds all items from the listbox to the document.

'Add items to the listbox
Private Sub cmdAddButton()
  If Not txtItems.Text = "" AND _
       cboItms = "FirstItem" OR cboItms.Listindex = 0 Then
       lstItms.Additem txtItems.Text
  EndIf
End Sub

'Add items to the document
Private Sub UpdateDocButton()
Dim i as Long
Dim j as Long
Dim strText as String
Dim oRng as Range

i= lstItms.Listcount
If i > 0 Then
   For j = 0 to i -1
       strText = strText & lstItms.Listindex(j) & vbCr
   Next

   'Add text to the bookmark, avoid deleting the bookmark
   Set oRng = _
         ActiveDocument.Bookmarks(cboItms).Range
   oRng.Text = strText
   Selection.Bookmarks.Add Name:=cboItms, Range:=oRng

   lstItms.Clear
EndIf
End Sub

I think you might have yet another topic not covered here or in your
question. What if the user wants to change items added to the listbox/ the
document. Usually the end-user is not all that interested in adding/typing
all items a second time before adding it to the document. You might have to
save the information in variables or retrieve the data from the bookmark
parsing the retrieved text where paragraph marks (vbCr) are found.

--
/Anna Bohman
Bra Utbildning AB, Sweden

http://www.buab.se
-------------------------------------------------------------------------



Quote:
> I am currently working on a multi-page userform which contains a
> ComboBox and a ListBox on one of the pages. I would like the user to
> be able to select an item in the ComboBox and then key a short list of
> items into the ListBox. The intention is that the contents of the
> ListBox will be then transferred to a bookmark in a Word document that
> corresponds with the ComboBox item.

> I've spent many hours trying (unsuccessfully) to do this.

> The process could be described as:

> If ComboBox item = XXX Then
> Type list into ListBox Then
> Send ListBox items to bookmark in document.

> Next ComboBox item .....
> Next list .....

> The ListBox items should appear in the document under headings with
> the same names as the ComboBox items. The process will be repeated for
> each of the items in the ComboBox.

> Any help in putting together the code to achieve this would be much
> appreciated. I'm very much a newbie at VBA programming.

> Regards

> Pat W



Fri, 12 Nov 2004 16:34:40 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using the pipe symbol to fill a listbox or combobox

2. Fill Listbox with Combobox possible?

3. Filling a ListBox from a ComboBox

4. how to fill a combobox with item and index

5. HOWTO fill in a ListBox or ComboBox

6. ensuring unique items in combobox/listbox

7. Randomly list items in listbox/combobox

8. It is possible to create a ListBox and combobox With Images in the items

9. It is possible to create a ListBox and combobox With Images in the items

10. Randomly list items in listbox/combobox

11. Filling a Secondary Combobox based on information from a primary combobox

12. removing a reference item from the project references option

 

 
Powered by phpBB® Forum Software