Loop without Do

S

Stephen Lynch

Can someone check my code. I keep getting a "loop without Do" error. If I
add another end if it just keeps running.

Thanks

*****************************************************


Private Sub LstboxLoansPending_DblClick(Cancel As Integer)
Dim rs As DAO.Recordset
Dim StrSQL As String

Dim strEmployeeIDContFile As String
Dim strEmployeeContAmt As Currency

EmployeeID = Me!LstboxLoansPending.Column(7)
ContributionAmt = Me!LstboxLoansPending.Column(3)

StrSQL = "SELECT tblContributionsTEMP.EmployeeID, tblContributionsTEMP.Loan1
AS LoanAmt " & vbCrLf & _
"FROM tblContributionsTEMP " & vbCrLf & _
"WHERE (((tblContributionsTEMP.Loan1)>0)); " & vbCrLf & _
"UNION SELECT tblContributionsTEMP.EmployeeID, tblContributionsTEMP.Loan2 AS
LoanAmt " & vbCrLf & _
"FROM tblContributionsTEMP " & vbCrLf & _
"WHERE (((tblContributionsTEMP.Loan2)>0)); " & vbCrLf & _
"UNION SELECT tblContributionsTEMP.EmployeeID, tblContributionsTEMP.Loan3 AS
LoanAmt " & vbCrLf & _
"FROM tblContributionsTEMP " & vbCrLf & _
"WHERE (((tblContributionsTEMP.Loan3)>0)); " & vbCrLf & _
"UNION SELECT tblContributionsTEMP.EmployeeID, tblContributionsTEMP.Loan4 AS
LoanAmt " & vbCrLf & _
"FROM tblContributionsTEMP " & vbCrLf & _
"WHERE (((tblContributionsTEMP.Loan4)>0));"

Set rs = CurrentDb.OpenRecordset(StrSQL, dbOpenDynaset)

Do While Not rs.EOF

strEmployeeIDContFile = rs.Fields("EmployeeID")
strEmployeeContAmt = rs.Fields("LoanAmt")

If strEmployeeIDContFile = EmployeeID Then
MsgBox "Found"
Else
MsgBox "Not Found"
rs.MoveNext
Loop
'MsgBox "Notfound"

End If
 
L

Linq Adams via AccessMonster.com

Newsgroup etiquette dictates if you find a solution yourself, or find a
solution elsewhere, that you post that solution. That way others researching
the same/similar problems can benefit. Just guessing, I would say that the
problem was that your **Do While** was before the beginning if your **If...
Then** construct and your **Loop** was between the **If...Then** and the
**End If.** The Access Gnomes always object to this.


Do While Not rs.EOF
.....
.....

If strEmployeeIDContFile = EmployeeID Then
.....
.....
.....
.....
Loop
.....

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top