Reaching the last record...

wilko

Registered User.
Local time
Today, 14:14
Joined
Feb 16, 2006
Messages
20
Hi Guys,

I am building a db where part of the functionality includes a practice tests. It is currently working well, with the form moving onto the next question when a student gets an answer correct, hoowever the problem comes when there are no questions left, the code still tries to move onto the next question, when there isnt one, thus causing a run-time error. Any hints/tips/advice on what I should consider to fix this would be much appreciated, here is the code:

Code:
open db with a sql-statement
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

'loop thru records
Dim i
i = 1
Do While Not rs.EOF
If rs!CorrectOrIncorrect = True Then
    Exit Do
End If
i = i + 1
rs.MoveNext
Loop
If Frame10.Value = i Then
    total = total + 1
    MsgBox "True" & total
        
    'command to go to next question
    DoCmd.GoToRecord , , acNext
    
    
ElseIf Frame10.Value <> i Then
    MsgBox "False"
    'show up boxes to see examples or theory
End If
'release resouces
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub

Cheers,

Ross
 
One thought, use error handling

ReleaseResouces:
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing


Errorx:
If Err.number = ? Then
MsgBox "Congrats, Test Over"

Else
MsgBox err.Number & "; " & err.Description
End If

Resume Release Resources

End Sub
 

Users who are viewing this thread

Back
Top Bottom