debugger help

jeremypaule

Registered User.
Local time
Today, 12:42
Joined
Aug 21, 2006
Messages
135
I’m running a loop through my recordset and when there is no data returned by the table it’ll give me the error.

Run-Time Error ‘3021’
No Current Record

How could I make it not go to the debugger and instead make it prompt a msgbox saying “No data”
 
i stuck this in there

On Error Resume Next

which will just do nothing if there is an error, is there a downside to this?
 
Jeremy,

Resume Next is not good! It will ignore ANY and ALL errors.

Code:
Set rst = CurrentDb.OpenRecordset("whatever sql you use")
While Not rst.EOF And Not rst.BOF
   ' Your Code here
   rst.MoveNext
   Wend

Wayne
 
this is how my code looks and it gets the error at.. " rst.MoveFirst "

so How could I make it not go to the debugger and instead make it prompt a msgbox saying “No data”?

rst.MoveFirst 'rst now contains first record from the query

While Not (rst.EOF)

tempstrg = rst!Account
tempstrg = tempstrg & "(" & rst!VAR & ")" & " "
fullstrng = fullstrng & tempstrg
rst.MoveNext

Wend 'end while

rst.Close
 
if you are getting an error at movefirst, your data file is empty.
You can p[ut a error handler in here, but you shouldn't need one
you will get an error if the rst you try to open doesn't exist eg bad query name, or if you handle the loop wrongly - otherwise no errors

so:

on error goto myhandler

set rst = etc
if rst.eof then goto whatever --- test for an empty file

only then

rst.MoveFirst 'rst now contains first record from the query

While Not (rst.EOF)

tempstrg = rst!Account
tempstrg = tempstrg & "(" & rst!VAR & ")" & " "
fullstrng = fullstrng & tempstrg
rst.MoveNext

Wend 'end while

exithere:
rst.close
exit sub

myhandler;
msgbox("Erorr: " & err.number & " Desc: " & err.decription)
resume exithere:

end sub
 
or could I take out rst.MoveFirst ? it seems to pull the right data if i take it out, would it make a difference if i did?
 
probably, I expect the recordset cursor is probably automatically placed at the start of the recordset. Moving it to the first record just explicitlly puts it there.

Perhaps someone can confirm wehether a recordset curosor is placed at the first record, or is undefined intiitally.
 
Try using this instead:

Code:
Do Until rst.EOF

tempstrg = rst!Account
tempstrg = tempstrg & "(" & rst!VAR & ")" & " "
fullstrng = fullstrng & tempstrg
rst.MoveNext

Loop
 

Users who are viewing this thread

Back
Top Bottom