Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete from list box

Status
Not open for further replies.

ashaikh05

MIS
Mar 2, 2007
13
GB
I've created 2 list boxes on a form so that i can select records from List1 (which looks up values from a table) and it will put them in List2.

How do i then delete a record from List2 if it is placed mistakenly?
 
That depends. How are you adding the items to List2?

Ed Metcalfe.

Please do not feed the trolls.....
 
Hi

Just to let you know that i'm a quite a beginner when it comes to programming.

I've created a command button with the following code in the onclick event.

Private Sub Command125_Click()
Dim lst1 As ListBox, lst2 As ListBox
Dim itm As Variant

Set lst1 = Me!List123
Set lst2 = Me!List126
' 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

Many thanks
 
Dim lst1 As ListBox, lst2 As ListBox
Dim itm As Variant

Set lst1 = Me!List1
Set lst2 = Me!List2
' 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)
lst1.RemoveItem 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)
lst1.RemoveItem itm
End If
End If
Next itm

Ed Metcalfe.

Please do not feed the trolls.....
 
delete a record from List2
As the RowSourceType property of List2 is set to "ValueList" you may consider the RemoveItem method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top