PDA

View Full Version : Multi-Select Listbox



twoolls
03-12-2012, 06:20 AM
I have created a userform that has a multi-select listbox which is linked to a text form field. When the text field is selected the userform opens and shows the list but no matter what I do I can't seem to get the selected results to populate to the text form field.

The code for the userform/listbox is:



Private Sub UserForm_Initialize()
With List1
.AddItem "Allergic Reaction"
.AddItem "Amputation"
.AddItem "Anxiety-Stress"
.AddItem "Ballistic Injury"
.AddItem "Bites-Stings"
.AddItem "Bruising"
.AddItem "Crushing Injury"
.AddItem "Cuts"
.AddItem "Dehydration"
.AddItem "Dislocation"
.AddItem "Explosive Injury"
.AddItem "Fatality"
.AddItem "Fatigue"
.AddItem "Fracture"
.AddItem "High Pressure Injury"
.AddItem "Impact Injury"
.AddItem "Needlestick"
.AddItem "Over Pressure Injury"
.AddItem "Puncture Wound"
.AddItem "Sprain"
.AddItem "Strain"
.AddItem "Unconsciousness"
.AddItem "Whiplash"
End With
End Sub

Private Sub CmdMovetoRight_Click()
Dim i As Integer
If List1.ListIndex = -1 Then
Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
List2.AddItem List1.List(i)
List1.RemoveItem I
End If
Next i
End Sub

Private Sub CmdMoveToLeft_Click()
Dim i As Integer
If List2.ListIndex = -1 Then
Exit Sub
For i = List2.ListCount - 1 To 0 Step -1
If List2.Selected(i) = True Then
List1.AddItem List2.List(i)
List2.RemoveItem I
End If
Next i
End Sub


Private Sub CommandButton1_Click()
Unload Me
End Sub



No matter what I try to do to get the results from List2 in to the text form field it doesn't seem to work.

Can anyone please help me?

Thanks

fumei
03-12-2012, 08:48 PM
When the text field is selected the userform opens
So you have an OnEnter macro that fires the userform?


but no matter what I do I can't seem to get the selected results to populate to the text form field.
But there is no code here that tries to do this.

twoolls
03-13-2012, 12:16 AM
The OnEntry macro that runs to bring up the userform is:



Sub ListBox()
UserForm1.Show
End Sub


I've tried adding the below in with the 'Unload Me' code to run when the userform is closed and also tried adding it as an OnExit macro but this doesn't work....


ActiveDocument.FormFields("Text2") = List2.Value

I guess this is the part I'm getting stuck at. Any thoughts?