This piece of code is used in a class module to delete an item form a collection of objects in that class. It also has to re-key the remaining items to match the indexes in a listbox so it always deletes the same item from the list and collection. It works for the first delete but then consistently deletes the item after the selected one. Can anyone see what is wrong with this code?
VB Code:
Public Sub DeleteControl(ByVal Index As Integer) 'delete item from collection Me.FormControls.Remove CStr(Index) ' change key for all collection items that are after deleted item ' remove item with key(index) and add it as key(index - 1) For Index = Index To FormControls.Count - 1 Me.FormControls.Add FormControls(CStr(Index + 1)), CStr(Index) Me.FormControls.Remove CStr(Index + 1) Next ENd sub




Reply With Quote