VBA inside DB loop not working

G

gci1000

Having some problem with VBA record set not being set correctly - probably a
bug in the code. Any help would be great. Run-time error. I have the
following code:

Set rs = CurrentDb.OpenRecordset("SELECT Code, LongCaption FROM MyTable")
Do While rs.EOF = False

longDescExists = False
If currentLongDesc = "" Then
' --> Code crashed here when it reaches this point for the 2nd time
Set rs2 = CurrentDb.OpenRecordset("SELECT Code, " & descName & "
FROM " & tblName & " RT Where RT.Code = 'B'")
WhichRs = "rs2"
If rs2.EOF = False Then
longDesc = rs2(1)
If longDesc <> "" Then longDescExists = True
End If

End If
End If

rs.MoveNext
Loop
rs.Close
rs2.Close
 

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