Throw in another if condition.
if rs <> nil then
if rs.EOF then
msgbox "No records found."
end
while not rs.EOF
...
rs.MoveNext
wend
else
...
Throw in another if condition.
if rs <> nil then
if rs.EOF then
msgbox "No records found."
end
while not rs.EOF
...
rs.MoveNext
wend
else
...
I just want to make sure there’s no error. No records are ok.
So
If Not db.Error Then
While rs<>Nil And Not rs.EOF
...
rs.MoveNext
Wend
Else
// Handle Error here if necessary...
End If
To keep my code very readable I have a simple method (called isDatabaseRecordSetError(db, rs)) that displays any error message in one line if either the database or the recordset has a problem and returns a Boolean. I can then decide to exit via Return or skip the next part of the code.
[quote]rs = db.SQLSelect(tempSQL)
if isDatabaseRecordSetError(db, rs) then Return
while not rs.EOF
wend
[/quote]
isDatabaseRecordSetError contains:
[quote]if myDatabase.Error then
MsgBox “There was an error with the database:” + myDatabase.ErrorMessage
Return True
elseif myRecordSet = nil then
MsgBox “There was an error reading the database records”
Return True
end if
Return False
[/quote]
If dealing with a SQLite Database I’ve always thrown a MoveFirst command before I start the loop through the records. Overkill, maybe, but it keeps me happy!