Loop without Do

arunakumari02

Registered User.
Local time
Today, 15:38
Joined
Jun 2, 2008
Messages
91
I have an error of loop without do in the code.

Any hint on it?

Code:
Private Sub Form_Open(Cancel As Integer)
 
   Dim Year1 As Integer
 
 
    'Size the form.
    InsideWidth = 1440 * 10
    InsideHeight = 1440 * 6
 
    chkResourceOptimizer = False
 
 
 
    txtYear1 = Format(CDate("1/1/" & Year(Date)), "yyyy")
 
    txtMonth1 = CDate("1/1/" & Year(Date))
    Debug.Print "txtMonth1"; txtMonth1
 
 
    For intMonth = 1 To 11
        Forms("frmPipeline")("txtMonth" & (intMonth + 1)) = DateAdd("m", intMonth, txtMonth1)
    Next
 
 
 
   lngRightHardStop = (linTimeLine.Left + linTimeLine.Width)
 
 
 
    strSQL = "SELECT * FROM tblProjects WHERE ResourceOptimizer=True ORDER BY ProjectID"
    Set rstProjects = CurrentDb.OpenRecordset(strSQL)
 
    If rstProjects.RecordCount > 0 Then
 
        rstProjects.MoveFirst
        'rstProjects.Move intRecordNumber
 
        intRow = 1
 
 
           Do Until rstProjects.EOF
 
 
 
            Forms!frmPipeline!("chkResourceOptimizer" & intRow) = True
            Forms!frmPipeline!("txtProjectID" & intRow) = rstProjects!ProjectID
            Forms!frmPipeline!("txtTitle" & intRow) = rstProjects!Title
            Forms!frmPipeline!("txtSEOwner" & intRow) = rstProjects!SEOwner
 
            'Alligning rectangular bars according to the start date.
            If Not IsNull(rstProjects!DateStarted) Then
 
                intExtractYear = DatePart("yyyy", rstProjects!DateStarted)
                Debug.Print "ExtractYear"; intExtractYear
                 intExtractMonth = DatePart("m", rstProjects!DateStarted)
                 Debug.Print "ExtractMonth"; intExtractMonth
                intDuration = rstProjects!Duration * 720
                 Debug.Print "Duration"; intDuration
 
            txtYear1 = Format(CDate("1/1/" & Year(Date)), "yyyy")
 
             If (txtYear1 = intExtractYear) Then
 
 
                    lngProjectBarLeft = linTimeLine.Left + ((intExtractMonth - 1) * 720)
 
 
                      If lngProjectBarLeft >= linTimeLine.Left And lngProjectBarLeft <= lngRightHardStop Then
                        Forms!frmPipeline("recBar" & intRow).Left = lngProjectBarLeft
                        Forms!frmPipeline("recBar" & intRow).Visible = True
                      ElseIf lngProjectBarLeft < linTimeLine.Left Then
                         lngProjectBarRight = linTimeLine.Left
 
                      End If
 
 
 
                   lngProjectBarRight = linTimeLine.Left + ((intExtractMonth - 1) * 720) + intDuration
                 'debug.Print "LngProjectBarRight"; lngProjectBarRight
 
                   If lngProjectBarRight >= linTimeLine.Left And lngProjectBarRight <= lngRightHardStop Then
 
                         Forms!frmPipeline("recBar" & intRow).Visible = True
                  ElseIf lngProjectBarRight > lngRightHardStop Then
 
                       lngProjectBarRight = lngRightHardStop
 
                    End If
            Else
                       Forms!frmPipeline("recBar" & intRow).Visible = False
             End If
 
            intRow = intRow + 1
            rstProjects.MoveNext
 
    Loop
 
    Else
                 MsgBox "No records are selected"
 
    End If  'End if recordcount > 0.
 
    rstProjects.Close
 
 End Sub
 
Last edited:
You have a problem with your If/End If. I count 5 If but only 4 End If.
 
You were missing an End If
Code:
Private Sub Form_Open(Cancel As Integer)

   Dim Year1 As Integer
   'Size the form.
   InsideWidth = 1440 * 10
   InsideHeight = 1440 * 6
   chkResourceOptimizer = False

   txtYear1 = Format(CDate("1/1/" & Year(Date)), "yyyy")

   txtMonth1 = CDate("1/1/" & Year(Date))
Debug.Print "txtMonth1"; txtMonth1

   For intMonth = 1 To 11
      Forms("frmPipeline")("txtMonth" & (intMonth + 1)) = DateAdd("m", intMonth, txtMonth1)
   Next

   lngRightHardStop = (linTimeLine.Left + linTimeLine.Width)

   strSQL = "SELECT * FROM tblProjects WHERE ResourceOptimizer=True ORDER BY ProjectID"
   Set rstProjects = CurrentDb.OpenRecordset(strSQL)

   If rstProjects.RecordCount > 0 Then

      rstProjects.MoveFirst
      'rstProjects.Move intRecordNumber

      intRow = 1

      Do Until rstProjects.EOF

         Forms!frmPipeline!("chkResourceOptimizer" & intRow) = True
         Forms!frmPipeline!("txtProjectID" & intRow) = rstProjects!ProjectID
         Forms!frmPipeline!("txtTitle" & intRow) = rstProjects!Title
         Forms!frmPipeline!("txtSEOwner" & intRow) = rstProjects!SEOwner

         'Alligning rectangular bars according to the start date.
         If Not IsNull(rstProjects!DateStarted) Then

            intExtractYear = DatePart("yyyy", rstProjects!DateStarted)
Debug.Print "ExtractYear"; intExtractYear
            intExtractMonth = DatePart("m", rstProjects!DateStarted)
Debug.Print "ExtractMonth"; intExtractMonth
            intDuration = rstProjects!Duration * 720
Debug.Print "Duration"; intDuration

            txtYear1 = Format(CDate("1/1/" & Year(Date)), "yyyy")

            If (txtYear1 = intExtractYear) Then

               lngProjectBarLeft = linTimeLine.Left + ((intExtractMonth - 1) * 720)

               If lngProjectBarLeft >= linTimeLine.Left And lngProjectBarLeft <= lngRightHardStop Then
                  Forms!frmPipeline("recBar" & intRow).Left = lngProjectBarLeft
                  Forms!frmPipeline("recBar" & intRow).Visible = True
               ElseIf lngProjectBarLeft < linTimeLine.Left Then
                  lngProjectBarRight = linTimeLine.Left
               End If

               lngProjectBarRight = linTimeLine.Left + ((intExtractMonth - 1) * 720) + intDuration
               'debug.Print "LngProjectBarRight"; lngProjectBarRight

               If lngProjectBarRight >= linTimeLine.Left And lngProjectBarRight <= lngRightHardStop Then
                  Forms!frmPipeline("recBar" & intRow).Visible = True
               ElseIf lngProjectBarRight > lngRightHardStop Then
                  lngProjectBarRight = lngRightHardStop
               End If
            Else
               Forms!frmPipeline("recBar" & intRow).Visible = False
            End If
            intRow = intRow + 1
            rstProjects.MoveNext
         [b][COLOR="Red"]End If[/COLOR][/b]
      Loop
   Else
      MsgBox "No records are selected"
   End If  'End if recordcount > 0.
   rstProjects.Close
End Sub
 

Users who are viewing this thread

Back
Top Bottom