I have 2 listbox named lstLeft and lstRight in a form.
I have inserted in form 2 button toleft and toright
When i click on button toright copy all items from lstLeft to lstRight and viceversa with the toright button..
How to?
move all items from left to right
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: move all items from left to right
Try:
Similar for the other.
Code: Select all
Private Sub toRight_Click()
Dim i As Long
' Make sure that lstRight is empty
Me.lstRight.Clear
' Loop through items of lstLeft
For i = 0 To Me.lstLeft.ListCount - 1
' Add item to lstRight
Me.lstRight.AddItem Me.lstLeft.List(i)
Next i
' Clear lstLeft
Me.lstLeft.Clear
End Sub
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: move all items from left to right
Wow! great code tks.HansV wrote:Try:
Similar for the other.Code: Select all
Private Sub toRight_Click() Dim i As Long ' Make sure that lstRight is empty Me.lstRight.Clear ' Loop through items of lstLeft For i = 0 To Me.lstLeft.ListCount - 1 ' Add item to lstRight Me.lstRight.AddItem Me.lstLeft.List(i) Next i ' Clear lstLeft Me.lstLeft.Clear End Sub