Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

For and If loops

Discussion in 'Information Technology' started by thusnani@gmail.com, Jul 28, 2006.

Tags:
  1. thusnani@gmail.com

    thusnani@gmail.com
    Expand Collapse
    Guest

    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
     
  2. thusnani@gmail.com

    thusnani@gmail.com
    Expand Collapse
    Guest

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

    Jeff Boyce
    Expand Collapse
    Guest

    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

    <thusnani@gmail.com> wrote in message
    news:1147972510.912821.134970@j55g2000cwa.googlegroups.com...
    > 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
    >
     

Share This Page