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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing elements from a listbox

Status
Not open for further replies.

limpan

Programmer
Joined
Jun 18, 2001
Messages
19
Location
SE
Can anyone help me?
I need to do a simple thing as removing an element from an unbound listbox.
As far as I know .Remove or .RemoveItem doesn´t work in Access. Does anyone know what does work?

Thanks,
Linus
 
Well limpan,
the following is from the Access '97 help topic on Selected Property

The following example uses the Selected property to move selected items in the lstSource list box to the lstDestination list box. The lstDestination list box's RowSourceType property is set to Value List and the control's RowSource property is constructed from all the selected items in the lstSource control. The lstSource list box's MultiSelect property is set to Extended. The CopySelected( ) function is called from the cmdCopyItem command button.

Code:
Sub cmdCopyItem_Click()
	CopySelected Me
End Sub

Function CopySelected(frm As Form) As Integer
	Dim ctlSource As Control
	Dim ctlDest As Control
	Dim strItems As String
	Dim intCurrentRow As Integer
	Set ctlSource = frm!lstSource
	Set ctlDest = frm!lstDestination
	For intCurrentRow = 0 To ctlSource.Listcount - 1
		If ctlSource.Selected(intCurrentRow) Then
			strItems = strItems & ctlSource.Column(0, intCurrentRow) & ";"
		End If
	Next intCurrentRow

' Reset destination control's RowSource property.
	ctlDest.RowSource = ""
	ctlDest.RowSource = strItems
End Function


Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top