Hello people,

I have a listbox that gets populated when a command button on the same form is clicked. When, the listbox gets populated, a listbox in another form is also getting populated at the same time.

The problem is that when I try to remove an item from a listbox, I have an error. I cannot remove the item from the listbox in another form.

These are the two codes that I tried.

VB Code:
  1. Dim Nm123 As String
  2.     Nm123 = lstOrder.Text
  3.     Dim ABC As Single
  4.     ABC = -1
  5.     Dim Trial As String
  6.     Dim DEF As String
  7.     DEF = ABC + 1
  8.    
  9.     For i = 1 To frmPizzaChoices.lstItems.ListCount
  10.    
  11.         Trial = frmPizzaChoices.lstItems.List(DEF)
  12.        
  13.         If Trial = lstOrder.Text Then
  14.        
  15.         frmPizzaChoices.lstItems.RemoveItem (DEF)
  16.        
  17.         End If
  18.    
  19.     Next i

This is a simpler code
VB Code:
  1. frmPizzaChoices.lstItems.RemoveItem (lstOrder.ListIndex)

Can someone please suggest a different way to display this.