![]() |
#1
|
|||
|
|||
![]()
Hello,
How do i insert a multiple selection dropdown list into my document? I have already inserted the listbox, and changed the multi-select to 2, but i have no idea what code to use. I just want the user to be able to select 1 or all options that i listed when completing the form. Thank you for your help! |
#2
|
||||
|
||||
![]()
You might use code along the lines of:
Code:
Private Sub CommandButton1_Click() Dim i As Long, StrOut As String For i = 0 To Me.ListBox1.ListCount - 1 If Me.ListBox1.Selected(i) Then StrOut = StrOut & Me.ListBox1.List(i) & vbCr End If Next i MsgBox StrOut End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
As for "How do I insert ...," it sounds like you have already achieved that. If you want to populate it then something like this:
Code:
Sub Document_new() With ListBox1 .Clear .MultiSelect = fmMultiSelectExtended .AddItem "A" .AddItem "B" .AddItem "C" .AddItem "D" End With End Sub |
#4
|
|||
|
|||
![]()
Thank you so much for your resbonse, but i'm very new to VBA and i'm lost (i appologize!) but so far this is what i did:
1. I inserted from the developer tab under activex the listbox 2. Went to properties and changed the multi-select to 2. 3. Went to view code...... now what? ![]() I pasted this and then turned design mode off, but there was no list. If you can give me any pointers i would greatly appreciate. Sorry!!! |
#5
|
||||
|
||||
![]()
Perhaps you could attach a document to a post with some representative data (delete anything sensitive) and your form, plus a description of what you want to have happen? You can attach a document to a post via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
![]()
You can see that i used checkboxes instead, but i would rather have all of these types of services listed in a dropdown so the user is able to select multiple options. I inserted the dropdown beside so you can see. I'm just not sure what's next.
Thank you! |
#7
|
||||
|
||||
![]()
See attached. You still haven't said, though, what you want done with the selected items.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
![]()
Hello, Thank you very much. This is exactly what I was looking for, I just simply wanted to have a multiple-selection dropdown list using the types of services that I had in the checkboxes.
Only one problem though, when i open it I get an error in the code screen "Compile error Only valid in object module" - is there anyway around this? I really just want to copy what you did here and insert it into my doc ![]() |
#9
|
||||
|
||||
![]()
I don't get that error when I open the document. Did you make any changes to it? You might also try repairing the Office installation (via Start > Windows Control Panel > Programs > Programs & Features > Microsoft Office (version) > Change > Repair).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
![]()
Thank you so very much macropod - it worked fine. I really do appreciate all of your help. Have a wonderful day!
|
#11
|
|||
|
|||
![]()
But the worry is it does not store the selection once you close the file. Any luck how the selection/s could be saved for next session.
|
#12
|
||||
|
||||
![]()
That is by design (i.e. that's a necessary limitation of using ActiveX controls). If you want to save the selection(s) for a later session, you would need to modify the code to both store those selections (e.g. in the document body or metadata) and re-select them after re-populating the ListBox.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
![]()
Hi
Is it possible to make the selected words from the dropdown appear in a list, instead of prompting, like in the example above? Best regards Martin |
#14
|
||||
|
||||
![]()
In the example I posted, the selected items in the list are highlighted; there is no 'prompting', as such.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
![]()
Alright.
Sorry for using the wrong words. I'm completely new to VBA, or coding in general! I don't know the syntax. Your example was very neat, and i've been trying to adapt to my needs. I have tried to read about this. Often "UserForms" are mentioned, but i don't know how to use those either. I've figured out the very basic stuff, like changing the selection type from "Multi" to "Extended", and change the list entries, but other than that i'm stuck. Is there a simple way to have the selected entries listed in a table column? Either adapting the number of rows to the number of selected items, or by just having enough row lines. It would simply make my day! Best regards, Martin |
![]() |
Tags |
form, multi drop down |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
spk | Word VBA | 43 | 07-31-2022 03:51 PM |
![]() |
trainsy | Word | 2 | 06-04-2014 04:43 AM |
block selection in dropdown list | Intruder | Excel | 2 | 01-10-2013 10:20 AM |
![]() |
coconutt | Word VBA | 5 | 09-13-2012 05:23 PM |
![]() |
biffle0764 | Word | 2 | 05-09-2012 12:54 PM |