For and If loops

T

thusnani

Im trying to put if loops in one for loop and im getting this error:
"Complie Error: Next without for"
Here is my code. What am i forgetting

Dim i As Integer
i = 1

For Each varItem In Me!ProjectList.ItemsSelected
project = Me!ProjectList.ItemData(varItem)
If i = 1 Then
Label1.Visible = True
Label1.Caption = project
Else
If i = 2 Then
Label2.Visible = True
Label2.Caption = project
Else
If i = 3 Then
Label3.Visible = True
Label3.Caption = project
Else
If i = 4 Then
Label4.Visible = True
Label4.Caption = project
Else
If i = 5 Then
Label5.Visible = True
Label5.Caption = project
Else
If i = 6 Then
Label6.Visible = True
Label6.Caption = project
Else
If i = 7 Then
Label7.Visible = True
Label7.Caption = project
Else
If i = 8 Then
Label8.Visible = True
Label8.Caption = project
Else
If i = 9 Then
Label9.Visible = True
Label9.Caption = project
Else
If i = 10 Then
Label10.Visible = True
Label10.Caption = project
End If
i = i + 1
Next varItem
 
T

thusnani

Sorry i answered my own question. I forgot to put each if statement as
elseif instead of else if
 
J

Jeff Boyce

A couple observations...

You appear to be using:

Else
If ...

when I think you need

ElseIf ...

Otherwise, you have a bunch of If ... Else... statements without their
respective EndIfs.

You might consider using a Select Case statement in place of multiple
If/Then statements.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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

Top