Compile Error: Variable not defined

brucerwalker

Registered User.
Local time
Today, 00:47
Joined
Sep 23, 2015
Messages
24
I have a form which we use to submit requests for testing in our lab. On this form we can add or remove part niumbers. When I try to remove a part number I get the error;
Compile Error: Variable not defined
the debugger them opens to the following code

Private Sub Command52_Click()
For I = 0 To List50.ListCount - 1
If List50.Selected(I) Then
List50.RemoveItem (I)
End If
Next I

End Sub

The first line is highlighted yellow. This form had been working fine. Can anyone suggest a solution to this problem? Thanks.
 
you have Option Explicit on your code header. just define the variable:

Private Sub Command52_Click()
Dim I as Integer
For I = 0 To List50.ListCount - 1
If List50.Selected(I) Then
List50.RemoveItem (I)
End If
Next I

you shouldn't do the loop forward, since when you delete from a list all other member of the list shifts to move up. do it:

for i = List50.ListCount-1 To 0 Step -1

End Sub
 

Users who are viewing this thread

Back
Top Bottom