For Without Next Error

B

Brad

I developed the following Visual Basic code from an example but when run I
get a "For Without Next" Error. What does this error mean? What this code
should accomplish is the selecting multiple items from the Available
Categories list and add them to the Selected Categories list.

Private Sub Add_Category_Click()
Dim VaxListCounter As Integer, VaxCurrentCounter As Integer
Dim VaxListItems As Integer, VaxCurrentItems As Integer
Dim ListStr As String, FoundInList As Integer
VaxListItems = [Available Categories].ListCount - 1
VaxCurrentItems = [Selected Categories].ListCount - 1
For VaxListCounter = 0 To VaxListItems
If [Available Categories].Selected(VaxListCounter) = True Then
If IsNull([Selected Categories].RowSource) Then
ListStr = [Available Categories].Column(0, VaxListCounter) & ";"
[Selected Categories].RowSource = ListStr
Else
FoundInList = False
For VaxCurrentCounter = 0 To VaxCurrentItems
If [Selected Categories].Column(0, VaxCurrentCounter) = _
[Available Categories].Column(0, VaxListCounter) Then
FoundInList = True
End If
Next VaxCurrentCounter
If Not FoundInList Then
ListStr = [Selected Categories].RowSource & _
[Available Categories].Column(0, VaxListCounter) & ";"
[Selected Categories].RowSource = ""
[Selected Categories].RowSource = ListStr
End If
End If
End If
 
R

Rick Brandt

Brad said:
I developed the following Visual Basic code from an example but when
run I get a "For Without Next" Error. What does this error mean?
What this code should accomplish is the selecting multiple items from
the Available Categories list and add them to the Selected Categories
list.

Private Sub Add_Category_Click()
Dim VaxListCounter As Integer, VaxCurrentCounter As Integer
Dim VaxListItems As Integer, VaxCurrentItems As Integer
Dim ListStr As String, FoundInList As Integer
VaxListItems = [Available Categories].ListCount - 1
VaxCurrentItems = [Selected Categories].ListCount - 1
For VaxListCounter = 0 To VaxListItems
If [Available Categories].Selected(VaxListCounter) = True Then
If IsNull([Selected Categories].RowSource) Then
ListStr = [Available Categories].Column(0,
VaxListCounter) & ";" [Selected Categories].RowSource =
ListStr Else
FoundInList = False
For VaxCurrentCounter = 0 To VaxCurrentItems
If [Selected Categories].Column(0, VaxCurrentCounter)
= _ [Available Categories].Column(0,
VaxListCounter) Then FoundInList = True
End If
Next VaxCurrentCounter
If Not FoundInList Then
ListStr = [Selected Categories].RowSource & _
[Available Categories].Column(0, VaxListCounter)
& ";" [Selected Categories].RowSource = ""
[Selected Categories].RowSource = ListStr
End If
End If
End If

Yep, every "For" needs a closing "Next" line. You have two "For"s and only one
"Next". Try adding...

Next VaxListCounter

....to the very end of the routine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top