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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What causes "Loop without Do' error if both are present?

Status
Not open for further replies.

sda7bobp

Technical User
Feb 14, 2005
28
US
In the following code, I get a compile error, "Loop without Do". What would cause that?

Code:
 Private Sub txtSurgeryID_LostFocus()
    
    Dim db As Database, rst As Recordset
    Dim strName As String, intResponse As Integer

    
        strName = "tblSurgery"
        
        Set db = CurrentDb
        Set rst = db.OpenRecordset(strName)
        rst.MoveFirst
            
            Do
                If rst.EOF Then
                    intResponse = MsgBox("The Surgery Code you entered is not in the Surgery Table.  " _
                        & "If you would like to try to enter a correct code, click Yes.  If you would like " _
                        & "to search for the procedure, click No.  If this is not a surgery case, " _
                        & "click Cancel and Edit the case.", vbCritical + vbYesNoCancel)
                        
                    If intResponse = 6 Then
                        Me!txtSurgeryID.SetFocus
                        rst.Close
                        Set db = Nothing
                        Exit Sub
                        
                    If intResponse = 7 Then
                        DoCmd.OpenForm "frmSelectSurgery", acNormal, , , , acWindowNormal
                    
                    If intResponse = 2 Then
                        DoCmd.Close
                        Exit Do
                    End If
                    
                If Me!txtSurgeryID = rst!SurgeryID Then
                        Me!txtSurgeryName = rst!SurgeryName
                        rst.Close
                        Set db = Nothing
                        Exit Sub
                        
                Else
                        rst.MoveNext
                End If
                
            Loop
            
    
End Sub


Bob
 
I think you need some ElseIf where you have used If for the second and third times when comparing the intResponse.

Then you have an Do If rst=... on separate lines. I think this should be Do Until rst =..... on one line

HTH
Mych
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top