Compile Error: Wend without WHile

mattaus

Registered User.
Local time
Today, 14:08
Joined
Apr 27, 2009
Messages
35
Hi I keep getting the above mentionted error can anybody help..?? Please look at the VBA below...Thanks

Code:
Public Sub Report_Run23(LOCReport As Recordset, datasheet As Variant, RepType As Integer) 'OUTPATINETS FOLLOW-UP'
Dim AppExcel As Object
Dim CurrentPG As String
Dim CurrentSheet As Variant
Dim SPos As Integer
Dim rpos As Integer
Dim cpos As Integer
Dim overeight As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim x As Integer
Dim y As Integer
Dim count As Integer
Dim Test1 As Variant
Dim Test2 As Variant
Dim Test3 As Variant
Dim StartDate As Date
Dim EndDate As Date
Dim NewDate As Date
Dim SumTotal As Single
Dim PG As String

' Start position of report data
rpos = 7
cpos = 2
' For 12 month reports
If RepType = 2 Then

End If

' Sets read start to begining of record
LOCReport.MoveFirst

' Counts number of fields in record
j = LOCReport.Fields.count

Select Case [Forms]![Test]![lstSpecialty]
Case "Cardiac Rehabilitation"
k = 37

End Select

Test1 = LOCReport.Fields(0).Name
Test2 = LOCReport.Fields(1).Name
Test3 = LOCReport.Fields(2).Name

StartDate = [Forms]![Test]![txtStartDate]
StartDate = DateAdd("d", -364, EndDate)

' For 12 month reports

While Not LOCReport.EOF


For y = 3 To 14

If LOCReport.Fields(0).Name = datasheet.Cells.Value(1, y) Then
datasheet.Cells.Value(43, y) = LOCReport.Fields(1)
NewDate = DateAdd("m", y - 1, StartDate)
datasheet.Cells(rpos, cpos + y).Value = DateAdd("m", i - 1, StartDate)
datasheet.Cells(rpos, cpos + y).NumberFormat = "mmmyy"



GoTo For_Y_Continue

LOCReport.MoveNext
Wend

LOCReport.Close
End If

End Sub
 
perhaps if you indent your code you can find the problem yourself??
Code:
Public Sub Report_Run23(LOCReport As Recordset, datasheet As Variant, RepType As Integer) 'OUTPATINETS FOLLOW-UP'
    Dim AppExcel As Object
    Dim CurrentPG As String
    Dim CurrentSheet As Variant
    Dim SPos As Integer
    Dim rpos As Integer
    Dim cpos As Integer
    Dim overeight As Integer
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim x As Integer
    Dim y As Integer
    Dim count As Integer
    Dim Test1 As Variant
    Dim Test2 As Variant
    Dim Test3 As Variant
    Dim StartDate As Date
    Dim EndDate As Date
    Dim NewDate As Date
    Dim SumTotal As Single
    Dim PG As String
    
    ' Start position of report data
    rpos = 7
    cpos = 2
      ' For 12 month reports
    If RepType = 2 Then
        
    End If
      
    ' Sets read start to begining of record
    LOCReport.MoveFirst
    
    ' Counts number of fields in record
    j = LOCReport.Fields.count
             
    Select Case [Forms]![Test]![lstSpecialty]
        Case "Cardiac Rehabilitation"
            k = 37
   
    End Select
    
    Test1 = LOCReport.Fields(0).Name
    Test2 = LOCReport.Fields(1).Name
    Test3 = LOCReport.Fields(2).Name
    
    StartDate = [Forms]![Test]![txtStartDate]
    StartDate = DateAdd("d", -364, EndDate)
    
    ' For 12 month reports
    
    While Not LOCReport.EOF
 
    
        For y = 3 To 14
        
            [B]If [/B]LOCReport.Fields(0).Name = datasheet.Cells.Value(1, y) Then
                datasheet.Cells.Value(43, y) = LOCReport.Fields(1)
                NewDate = DateAdd("m", y - 1, StartDate)
                datasheet.Cells(rpos, cpos + y).Value = DateAdd("m", i - 1, StartDate)
                datasheet.Cells(rpos, cpos + y).NumberFormat = "mmmyy"
                
               
            
            GoTo For_Y_Continue
        
            LOCReport.MoveNext
        Wend
       
        LOCReport.Close
    End If
            
End Sub
 
I found the problem, thanks o supreme uber great fantastic supercalefragelistic majestic mr ma

Thanks
 

Users who are viewing this thread

Back
Top Bottom