In the following code, I get a compile error, "Loop without Do". What would cause that?
Bob
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