Wasnt sure what sub-forum to post this in so went for this one and the VBA one!
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:
Cheers,
Ross
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