PC Review


Reply
Thread Tools Rate Thread

For and If loops

 
 
thusnani@gmail.com
Guest
Posts: n/a
 
      18th May 2006
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

 
Reply With Quote
 
 
 
 
thusnani@gmail.com
Guest
Posts: n/a
 
      18th May 2006
Sorry i answered my own question. I forgot to put each if statement as
elseif instead of else if

 
Reply With Quote
 
Jeff Boyce
Guest
Posts: n/a
 
      18th May 2006
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

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loops Mbenenge@gmail.com Microsoft Excel Discussion 4 14th Sep 2007 06:23 PM
VBA Loops Chris Microsoft Excel Discussion 1 19th Nov 2004 01:51 PM
Loops Microsoft Excel Worksheet Functions 3 13th May 2004 03:12 PM
LOOPS Fernando Duran Microsoft Excel Programming 2 3rd Sep 2003 01:07 AM
Re: Loops Tom Ogilvy Microsoft Excel Programming 0 18th Jul 2003 05:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:34 AM.