472,127 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Previous/Next Question

Can anyone please help me on how to move to the next and previous
question?

Here is a snippet of my code:

Private Sub cmdNext_Click()
End Sub

Private Sub cmdPrevious_Click()
showrecord
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 0 To 3
Check1(i).BackColor = RGB(255, 255, 255)
Next
temstr = App.Path + "\testengine.mdb"
Set db = OpenDatabase(temstr)
initialise
End Sub
Sub initialise()
Dim i As Integer
Dim j As Integer
j = 0
Set rs = db.OpenRecordset("Select QuestionNo From QMultiple Where
Selected = True Order By QuestionNo")
rs.MoveFirst
While rs.EOF = False
j = j + 1
selquestion(j) = rs!questionno
rs.MoveNext
Wend
showrecord (1) 'Show first question
End Sub

Function quizscore() As Integer 'Returnes user's current score
Dim score As Integer
Dim i As Integer
For i = 1 To 20
Set rs = db.OpenRecordset("select solution from qmultiple where
questionno=" & selquestion(i))
If rs!solution = attempted(i - 1) Then
score = score + 1
Next
quizscore = score
End Function
Sub showrecord(n As Integer) 'Displays question with qno=n
Set rs = db.OpenRecordset("select * from qmultiple where questionno="
& selquestion(n))
With frmQuiz
..lblQuestion = rs!question
..Check1(0).Caption = rs!ans1
..Check1(0).Value = Val(Mid(attempted(n - 1), 1, 1))
..Check1(1).Caption = rs!ans2
..Check1(1).Value = Val(Mid(attempted(n - 1), 2, 1))
..Check1(2).Caption = rs!ans3
..Check1(2).Value = Val(Mid(attempted(n - 1), 3, 1))
..Check1(3).Caption = rs!ans4
..Check1(3).Value = Val(Mid(attempted(n - 1), 4, 1))
..lblQNo.Caption = n
End With
End Sub

I want to move to the next question using the cmdNext button and move
to the last question using the cmdPrevious button.

Thanks guys.
Jul 17 '05 #1
1 2889

"Mohammed Mazid" <ka******@hotmail.com> wrote in message
news:7c**************************@posting.google.c om...
Can anyone please help me on how to move to the next and previous
question?

Here is a snippet of my code:

Private Sub cmdNext_Click()
End Sub

Private Sub cmdPrevious_Click()
showrecord
End Sub
Sub showrecord(n As Integer) 'Displays question with qno=n

Set rs = db.OpenRecordset("select * from qmultiple where questionno="
& selquestion(n))
With frmQuiz
.lblQuestion = rs!question
.....
End With
End Sub

I want to move to the next question using the cmdNext button and move
to the last question using the cmdPrevious button.


Since you like the idea of retrieving the question every time (see other
posts), try this:

'form level variable
Private mQNum as Long

Sub ShowRecord(n As Integer)
'Displays question with qno=n
Set rs = db.OpenRecordset("select * from qmultiple "
& " where questionno=" & selquestion(n))
'store the new current question number
mQNum = n
With frmQuiz
lblQuestion = rs!question
'.....etc
End With
End Sub

Private Sub cmdNext_Click()
Call ShowRecord(mQNum+1)
End Sub

Private Sub cmdPrevious_Click()
Call ShowRecord(mQNum-1)
End Sub

It might be an idea to check somewhere for QNum < 1 or QNum >
NumOfQuestions....

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Leroy | last post: by
3 posts views Thread by Marcel | last post: by
24 posts views Thread by Ian Rastall | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.