Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile error: Loop with do

Status
Not open for further replies.

mohebk

MIS
Aug 23, 2005
139
US
Hi,
Using MS Access 2003

I have some functions that I created in module long time a go. I am getting a compile error on all of them on the loop line. The error said "Compile Error: Loop without do".

They were working at some point. I think I am missing a reference library or something.

Please help.

Thanks

Mo
 
Sounds like you have a "loop without do". Maybe post some relevant code?

_________________
Bob Rashkin
 
Hi,
This is the entire function code:
Thanks

Function HerniaRepair()

Dim sqlStr As String
Dim rst As DAO.Recordset
Dim sqlInsert As String


Dim lName As String
Dim lMrn As String
Dim lInvNum As String
Dim lCpt As String
Dim lCpt54640 As Boolean
Dim lCptOverlap As Boolean
Dim lDOS As Date
Dim lProv As String
Dim PrevName As String
Dim PrevMrn As String
Dim PrevInvNum As String
Dim PrevCpt As String
Dim PrevDOS As Date
Dim PrevProv As String
Dim dummy

DoCmd.SetWarnings False
sqlStr = "SELECT * FROM URO_HERNIA_REPAIR_040909 ORDER BY invnum, cpt Desc "
Set rst = CurrentDb.OpenRecordset(sqlStr, dbOpenDynaset)
Debug.Print sqlStr

lName = rst!patname
lMrn = rst!mrn
lInvNum = rst!invnum
lCpt = rst!cpt
lDOS = rst!dos
lProv = rst!prov

With rst
Do Until rst.EOF
If rst!invnum = lInvNum Then
If rst!cpt = "54640" Then
lCpt54640 = True
End If
If rst!cpt = "49500" Or rst!cpt = "49501" Or rst!cpt = "49502" Or rst!cpt = "49503" Or rst!cpt = "49504" Or rst!cpt = "49505" Or rst!cpt = "49506" Or rst!cpt = "49507" And lCpt54640 = True Then
lCptOverlap = True
End If
PrevName = rst!patname
PrevMrn = rst!mrn
PrevInvNum = rst!invnum
PrevCpt = rst!cpt
PrevDOS = rst!dos
PrevProv = rst!prov

Else
If lCptOverlap = True Then
sqlInsert = "Insert into URO_HERNIA_REPAIR_UNIQUE (patname, mrn, invnum, DOS, PROV, cpt) " & " values ('" & Nz(pervName, "") & "','" & Nz(PrevMrn, "") & "','" & Nz(PrevInvNum, "") & "','" & Nz(PrevDOS, "") & "','" & Nz(PrevProv, "") & "','" & Nz(PrevCpt, "") & "')"
Debug.Print sqlInsert
DoCmd.RunSQL sqlInsert

lName = rst!patname
lMrn = rst!mrn
lInvNum = rst!invnum
lCpt = rst!cpt
lDOS = rst!dos
lProv = rst!prov
lCpt54640 = False
lCptOverlap = False

If rst!cpt = "54640" Then
lCpt54640 = True
End If
If rst!cpt = "49500" Or rst!cpt = "49501" Or rst!cpt = "49502" Or rst!cpt = "49503" Or rst!cpt = "49504" Or rst!cpt = "49505" Or rst!cpt = "49506" Or rst!cpt = "49507" And lCpt54640 = True Then
lCptOverlap = True
End If
PrevName = rst!patname
PrevMrn = rst!mrn
PrevInvNum = rst!invnum
PrevCpt = rst!cpt
PrevDOS = rst!dos
PrevProv = rst!prov
End If
rst.MoveNext
Loop
If lCptOverlap = True Then
sqlInsert = "Insert into URO_HERNIA_REPAIR_UNIQUE (patname,mrn,invnum,cpt) " & " values ('" & Nz(pervName, "") & "','" & Nz(PrevMrn, "") & "','" & Nz(PrevInvNum, "") & "','" & Nz(PrevCpt, "") & "')"
Debug.Print sqlInsert
DoCmd.RunSQL sqlInsert
End If

rst.Close
DoCmd.SetWarnings True
End With

End Function


Mo
 
I should add that I placed a couple breaks and it does not look like the rst is getting loaded with data.

Mo
 
Unbalanced If/end If !
I'd replace this:
Else
If lCptOverlap = True Then
with this:
ElseIf lCptOverlap = True Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Mo,

you are missing one "End If". This condition:
Code:
                Else
                    If lCptOverlap = True Then
has no concluding end if. So it is not a loop without do, but a missing end if.

Cheers,
miS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
I see, PHV was faster.
:p

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Thank you both.

I did that and got rid of the compiling error. But I have this function triggered by a command button on a form. It seems to run with out errors but it does not process the data. It opens the code window and nothing happens. But if I step through the code it works fine. Not sure.


Mo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top