Teppic
12-16-2003, 08:41 AM
im trying to create a program that loads questions and then the correct answer is chosen from 4 available i have got most of this working but one thing i cant get to work is the .eof. below is the part of my code i am struggling with it debugs on this line
If Not Data1.Recordset.EOF Then
with error "object variable or with block variable not set
can some one please tell me where im going wrong or any other suggestions to do what im trying to do with this piece of code.
the code is from sub question as seen bellow and the whole code is below that
Private Sub Question()
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
Else
frm1.Show
End If
End Sub
Dim Score As Integer
Dim Queno As Integer
Private Declare Function sndPlaySound Lib _
"winmm.dll" Alias "sndPlaySoundA" (ByVal _
lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub cmd1_Click()
Dim Choose As Integer
Choose = 0
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub cmd2_Click()
Dim Choose As Integer
Choose = 1
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub cmd3_Click()
Dim Choose As Integer
Choose = 2
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub cmd4_Click()
Dim Choose As Integer
Choose = 3
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub ButtonDim()
frmQuiz.cmd1.Enabled = False
frmQuiz.cmd2.Enabled = False
frmQuiz.cmd3.Enabled = False
frmQuiz.cmd4.Enabled = False
End Sub
Public Function choice(Choose As Integer)
ButtonDim
If Choose = frmQuiz.lblCorrect Then
frmQuiz.lblTF.Visible = True
frmQuiz.lblTF = "CORRECT"
sndPlaySound App.Path & "\" & "correct.wav", &H1
Score = Score + 1
Else
frmQuiz.lblTF.Visible = True
sndPlaySound App.Path & "\" & "wrong.wav", &H1
frmQuiz.lblTF = "WRONG"
End If
End Function
Private Sub cmdExit_Click()
Dim MsgText As String
Dim temp As String
MsgText = "Do you really want to Exit"
temp = MsgBox(MsgText, vbYesNo)
If temp = vbYes Then
Unload Me
Else
frmQuiz.Show
End If
Exit Sub
End Sub
Private Sub Form_Load()
Question
Score = 0
Queno = 1
Failed = 0
Passed = 0
End Sub
Private Sub Question()
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
Else
frm1.Show
End If
End Sub
Private Sub ButtonAble()
frmQuiz.lblTF.Caption = " "
frmQuiz.cmd1.Enabled = True
frmQuiz.cmd2.Enabled = True
frmQuiz.cmd3.Enabled = True
frmQuiz.cmd4.Enabled = True
frmQuiz.Next.Enabled = False
End Sub
Private Sub Next_Timer()
Queno = Queno + 1
frmQuiz.lblQueno.Caption = Queno
Question
ButtonAble
End Sub
If Not Data1.Recordset.EOF Then
with error "object variable or with block variable not set
can some one please tell me where im going wrong or any other suggestions to do what im trying to do with this piece of code.
the code is from sub question as seen bellow and the whole code is below that
Private Sub Question()
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
Else
frm1.Show
End If
End Sub
Dim Score As Integer
Dim Queno As Integer
Private Declare Function sndPlaySound Lib _
"winmm.dll" Alias "sndPlaySoundA" (ByVal _
lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub cmd1_Click()
Dim Choose As Integer
Choose = 0
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub cmd2_Click()
Dim Choose As Integer
Choose = 1
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub cmd3_Click()
Dim Choose As Integer
Choose = 2
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub cmd4_Click()
Dim Choose As Integer
Choose = 3
frmQuiz.Next.Enabled = True
choice (Choose)
End Sub
Private Sub ButtonDim()
frmQuiz.cmd1.Enabled = False
frmQuiz.cmd2.Enabled = False
frmQuiz.cmd3.Enabled = False
frmQuiz.cmd4.Enabled = False
End Sub
Public Function choice(Choose As Integer)
ButtonDim
If Choose = frmQuiz.lblCorrect Then
frmQuiz.lblTF.Visible = True
frmQuiz.lblTF = "CORRECT"
sndPlaySound App.Path & "\" & "correct.wav", &H1
Score = Score + 1
Else
frmQuiz.lblTF.Visible = True
sndPlaySound App.Path & "\" & "wrong.wav", &H1
frmQuiz.lblTF = "WRONG"
End If
End Function
Private Sub cmdExit_Click()
Dim MsgText As String
Dim temp As String
MsgText = "Do you really want to Exit"
temp = MsgBox(MsgText, vbYesNo)
If temp = vbYes Then
Unload Me
Else
frmQuiz.Show
End If
Exit Sub
End Sub
Private Sub Form_Load()
Question
Score = 0
Queno = 1
Failed = 0
Passed = 0
End Sub
Private Sub Question()
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
Else
frm1.Show
End If
End Sub
Private Sub ButtonAble()
frmQuiz.lblTF.Caption = " "
frmQuiz.cmd1.Enabled = True
frmQuiz.cmd2.Enabled = True
frmQuiz.cmd3.Enabled = True
frmQuiz.cmd4.Enabled = True
frmQuiz.Next.Enabled = False
End Sub
Private Sub Next_Timer()
Queno = Queno + 1
frmQuiz.lblQueno.Caption = Queno
Question
ButtonAble
End Sub