.eof from access database problem

Teppic
12-16-2003, 09: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

Dennis DVR
12-16-2003, 09:45 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


try to refresh the ado or dao control
data1.recordset.refresh


Private Sub Question()
Data1.Recordset.Refresh
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
Else
frm1.Show
End If

End Sub

Teppic
12-16-2003, 09:49 AM
it didnt like that either

it gave the same error on the new line

thank you for trying though

anyother ideas

VeRiTo
12-16-2003, 09:50 AM
where is Data1 setted? declared?
what is Data1?

Teppic
12-16-2003, 10:02 AM
where is Data1 setted? declared?
what is Data1?

i havent done that properly as im not sure how i tried it like

set quest = data1.recordset
do while not quest.eof

and could not get that to work either

im sure im just missing something really simple but i have done little work with vb and none with database linking sorry

VeRiTo
12-16-2003, 10:06 AM
Try this:

Set quest = New Recordset
Set quest = data1.Recordset

Dennis DVR
12-16-2003, 10:13 AM
Try this:

Set quest = New Recordset
Set quest = data1.Recordset


try this one

Teppic
12-16-2003, 10:18 AM
i tried that and it wouldnt work

could u pls write the whole sub as im not sure if im doing it right

plus any other things i need to set or declare thank u

Dennis DVR
12-16-2003, 10:19 AM
i tried that and it wouldnt work

could u pls write the whole sub as im not sure if im doing it right

plus any other things i need to set or declare thank u

submit the code and the database instead.

VeRiTo
12-16-2003, 10:36 AM
do You get The error here?

Private Sub Question()

If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
Else
frm1.Show
End If

End Sub

where in code do you set quest=data1.recordset?
what type is data1.recordset?

I cant help you with your partial code..

Teppic
12-16-2003, 10:37 AM
i uploaded everything to here

http://homepage.ntlworld.com/jason.pinnegar/Practicle%20VB/

VeRiTo
12-16-2003, 10:46 AM
i dont get any error you said...

Dennis DVR
12-16-2003, 10:47 AM
i dont get any error you said...

mine too
try to make a new project

Teppic
12-16-2003, 11:09 AM
did u try to the last question when it debugs

it doesnt have ne eof in it at the mo as i have not saved that in it as its not worrking

Dennis DVR
12-16-2003, 11:19 AM
did u try to the last question when it debugs

it doesnt have ne eof in it at the mo as i have not saved that in it as its not worrking


Private Sub Question()
Data1.Refresh
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
Else
frm1.Show
End If

End Sub

refresh the data control before using it as i have posted a while ago

Teppic
12-16-2003, 11:33 AM
ive added that to the prgect and now it only loads the second question over and over

i think when it refreshes the data it takes it back to the first record
then the .movenext takes it to the second

so how do i stop it going back to the first record

Dennis DVR
12-16-2003, 11:35 AM
ive added that to the prgect and now it only loads the second question over and over

i think when it refreshes the data it takes it back to the first record
then the .movenext takes it to the second

so how do i stop it going back to the first record

put the Data1.Refresh on form_load event

Private Sub Form_Load()
Data1.Refresh
End Sub

Teppic
12-16-2003, 12:15 PM
now its not loading the first question and its still not showing form1 when it .EOF

:(

Dennis DVR
12-16-2003, 07:47 PM
now its not loading the first question and its still not showing form1 when it .EOF

:(

try this project i did some modification on your program
just change the connection of your dao control.

if it didn't work try the code below


Private Sub Question()

If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
if Data1.Recordset.EOF then
frm1.show
end if
end if

End sub

and on your form_load event
Private Sub Form_Load()
Data1.Refresh
'Question --- Remark this thing coz this will skip to next question
etc.
etc.
end sub


End Sub

Dennis DVR
12-17-2003, 11:53 AM
did you try the code?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum