Good afternoon
I have a subroutine, which is intended to transfer a name from one listbox to another:
For some reason, this works fine but every now and then it stalls, at the .removeitem line, because it's trying to remove item 1 in a listbox containing only one item. I can't work out what I've misssed.
Any ideas?
Thanks
Chris
I have a subroutine, which is intended to transfer a name from one listbox to another:
VBA Code:
'Initialise End Of List flag
booEndOfList = False
lngLoopCount = 0
With lstLocations
While booEndOfList = False
'Check if we have reached the end of the list
If lngLoopCount = .ListCount Then
booEndOfList = True
Else
'Check if it is selected
If .Selected(lngLoopCount) = True Then
'Capture the location name
strLocName = .List(lngLoopCount)
'Transfer across and remove from the original list
lngListPos = insertItem(lstMainLocs, strLocName)
.RemoveItem (lngLoopCount)
'Mark as selected
With colLocations.Item(strLocName)
.locSelected = True
End With
Else
'If not selected, move to next item in list
lngLoopCount = lngLoopCount + 1
End If
End If
Wend
End With
For some reason, this works fine but every now and then it stalls, at the .removeitem line, because it's trying to remove item 1 in a listbox containing only one item. I can't work out what I've misssed.
Any ideas?
Thanks
Chris