G
Guest
Real simple question more than likely. I have searched the forums but can't
seem to find where this has been answered before so here goes...
I am doing a mock-up for a possible application. I have a simple form with
two list boxes and two command buttons.
The first box contains records based on a drop down combo box's value.
Everything works fine with List Box 1.
List box 2 is the problem. I was able to use the following to add values
from list box 1 with no problem:
Private Sub cmdAdd_Detail_Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim strSQL As String, strMsg As String
Dim itm As Variant
Set lst1 = Me.LstAvailable
Set lst2 = Me.lstDetail
lst2.RowSourceType = "Value List"
' Check selected items.
For Each itm In lst1.ItemsSelected
' Set RowSource property for first selected item.
If lst2.RowSource = "" Then
lst2.RowSource = lst1.ItemData(itm)
Else
' Check whether item has already been copied.
If Not InStr(lst2.RowSource, lst1.ItemData(itm)) > 0 Then
lst2.RowSource = lst2.RowSource & ";" & lst1.ItemData(itm)
End If
End If
Next itm
End Sub
That all works perfectly as I would like it to. The problem is... that the
other command button I have is to remove an item from list 2 after the user
decides they dont want it anymore. (or multiple items). So... I am kind of
confused as to how go about this. I thought it would be something simple
like:
List2.rowsource = list2.rowsource - list2.itemdata(itm)
but as I am sure you are aware.. that didn't work.
Any help is greatly appreciated and I am sure it is a very simple solution I
have just overlooked.
Thanks in advance.
seem to find where this has been answered before so here goes...
I am doing a mock-up for a possible application. I have a simple form with
two list boxes and two command buttons.
The first box contains records based on a drop down combo box's value.
Everything works fine with List Box 1.
List box 2 is the problem. I was able to use the following to add values
from list box 1 with no problem:
Private Sub cmdAdd_Detail_Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim strSQL As String, strMsg As String
Dim itm As Variant
Set lst1 = Me.LstAvailable
Set lst2 = Me.lstDetail
lst2.RowSourceType = "Value List"
' Check selected items.
For Each itm In lst1.ItemsSelected
' Set RowSource property for first selected item.
If lst2.RowSource = "" Then
lst2.RowSource = lst1.ItemData(itm)
Else
' Check whether item has already been copied.
If Not InStr(lst2.RowSource, lst1.ItemData(itm)) > 0 Then
lst2.RowSource = lst2.RowSource & ";" & lst1.ItemData(itm)
End If
End If
Next itm
End Sub
That all works perfectly as I would like it to. The problem is... that the
other command button I have is to remove an item from list 2 after the user
decides they dont want it anymore. (or multiple items). So... I am kind of
confused as to how go about this. I thought it would be something simple
like:
List2.rowsource = list2.rowsource - list2.itemdata(itm)
but as I am sure you are aware.. that didn't work.
Any help is greatly appreciated and I am sure it is a very simple solution I
have just overlooked.
Thanks in advance.