PDA

View Full Version : Solved: Multiselect listbox



lifeson
09-14-2007, 11:57 AM
Friday night and still working :banghead:

I have a list box (lstAcc) which is set up as a multiselect option and I want to display a userform (frmAccQty) for each item selected in the listbox.

Its a list of accessories available for a component and the user selects the accessories they require from the list box and then a user form is diplayed asking how many of each item they want.

I have this so far: :think:

Private Sub cmdSelect_Click()
Dim iItem As Long
lstAcc.BoundColumn = 2

If lstAcc.ListIndex = -1 Then
msg = "No item has been selected," & vbNewLine
msg = msg & "Select an item from the list to add"
ans = MsgBox(msg, vbExclamation)
Else
For iItem = 0 To lstAcc.ListCount - 1
If lstAcc.Selected(iItem) = True Then
FrmAccQty.Show
lstAcc.Selected(iItem) = False
End If
Next
End If

End Sub

The user form code is
Private Sub UserForm_Initialize()
Dim desc As String
desc = FrmBlrDetail.lstAcc.Value
txtDesc = desc
txtQty.SetFocus
End Sub

Norie
09-14-2007, 12:27 PM
Why a seperate userform for each item selected?

lifeson
09-14-2007, 12:42 PM
Why a seperate userform for each item selected?

So the user can add a quantity against each item in the list
Its the same form for all items and just shows the description of the item and a textbox for the quantity required

It would be easier if the user could add the quatinty required against each item in the list and then all items (x qty) could be added in one go, but I don't think you can do that with a listbox control?

Norie
09-14-2007, 12:52 PM
Well no you can't do that with just a listbox.

But I can think of various other approachs.

Perhaps a combobox and listbox.

User chooses from combobox, code is triggered, they are asked for the quantity, perhaps via a simple inputbox, and then both the item and quantity are added to the listbox.

You could also have other controls to remove/alter items in the listbox.

lifeson
09-15-2007, 01:27 AM
I am nearly there.
I have attached an example

When the user selects the items in the list I have added a message box which shows the item that has been selected but I cant get it to pass that value to the second form to add a quantity

Bob Phillips
09-15-2007, 03:12 AM
Here you go

lifeson
09-15-2007, 05:17 AM
Obviously I was nowhere near :doh:
Iwas hoping that it would have passed the description of the accesory (boundcolumn 2 not the part ID)
Changing the bound column doesnt seem to make any difference.

I'll have a play

Again thanks:clap:

Bob Phillips
09-15-2007, 06:09 AM
Just change this line



val = lstAcc.List(iitem)


to



val = lstAcc.List(iitem, 1)