eof and error 3021

G

Guest

I have tried checking for eof in various places in the following code.
However, I always get the 3021 error saying there is no current record. Any
help would be appreciated. I am using Access 2003.

While Not rs.EOF And lngID = rs("TrnID") And strTo =
rs("EmailAddress")
If rs.EOF Then
GoTo SendEmail
End If
If Not IsNull(rs("TrnHdr")) Then
strEMsg = strEMsg & rs("TrnHdr") & vbCr
End If
If Not IsNull(rs("TrnDtl")) Then
strEMsg = strEMsg & " " & rs("TrnDtl") & vbCr
End If
If Not IsNull(rs("TrnHdr")) Or Not IsNull(rs("TrnDtl")) Then
strEMsg = strEMsg & vbCr
End If
If rs.EOF Then
GoTo SendEmail
End If
rs.MoveNext
Wend
 
G

Guest

The problem is on this line:
While Not rs.EOF And lngID = rs("TrnID") And strTo = rs("EmailAddress")

All 3 conditions are checked even if the first is False. In this case, you
are checking the value of fields in the recordset even after you hit EOF.
That is why you get the error.

You will need to check for EOF it by itself, then check the others.

While Not rs.EOF
If lngID <> rs![TrnID] Or strTo <> rs![EmailAddress] Then
Exit Do
End If

Also, get rid of the GoTo statments. The only time it is socially
acceptable to use GoTo is in error handling.
 

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