Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with EOF

Status
Not open for further replies.

azamatali

Programmer
Aug 20, 2001
50
IN
hi folks,

While Not rssearch.EOF

List1.AddItem rssearch(1)
rssearch.MoveNext

Wend
This code is giving problems since on the last record the eof is false but when rssearch.movenext is given.. it goes to eof which results in an error..
 
Hi,

Try:

---------------------------------------------------
If Not(rssearch.EOF and rssearch.BOF) then
While Not rssearch.EOF
List1.AddItem rssearch.fields(1)
rssearch.MoveNext
Wend
else
'Empty recordset
end if
---------------------------------------------------
That should work.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
hi sunaj,
i think u did'nt got the problem.. the problem is that when the pointer is on the last record.. the eof property is false and it goes into the while loop ...
Now in the loop rs.movenext takes it to the eof where it gives an error..
I hope u get it..
 
I got it the first time.
This is 100% standard code I've used it hundreds of times and it works. Are you sure that you copied my code exactly? there was a mistake in your code:
List1.AddItem rssearch(1) should be
List1.AddItem rssearch.fields(1)

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
hi sunaj,
This is giving an error due to the reason i explained u before please look into more detail.. and help me
My code is:


'Getting all disease from the database to the all list
Dim rsdis As New ADODB.Recordset
Set rsdis = conn.Execute("select * from alldiseases")

If Not (rsdis.EOF And rsdis.BOF) Then
While Not rsdis.EOF
List1.AddItem rsdis!diseasename
rsdis.MoveNext
Wend
End If
 

Hi,

There should be a rsdis.movefirst to populate the recordset, I also missed that in my first code - sorry.


---------------------------------------------------------
Dim rsdis As New ADODB.Recordset
Set rsdis = conn.Execute("select * from alldiseases")

If Not (rsdis.EOF And rsdis.BOF) Then
rddis.movefirst
While Not rsdis.EOF
List1.AddItem rsdis!diseasename
rsdis.MoveNext
Wend
End If
----------------------------------------------------------

Here is a piece of code that I use and I know works:
----------------------------------------------------------
Private Sub Command1_Click()
Dim con As ADODB.Connection
Dim rst As Recordset, StrCon As String

StrCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\tmp\test.mdb"
Set con = New ADODB.Connection
con.Open StrCon

Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM TblTest", con, adOpenStatic, adLockOptimistic 'edit the SQL statement here
If Not (rst.EOF And rst.BOF) Then
rst.MoveFirst
While Not rst.EOF
List1.AddItem rst.Fields(0) 'you can replace the '0' with your fieldname
rst.MoveNext
Wend
Else
List1.AddItem "No records in recordset"
End If
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing
End Sub
----------------------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Not sure, don't have time right now to check it out, but I seem to recall getting an error on movenext to eof = true with forward-only rs. Maybe make it a static rs? (Your code looks fine to me) Tim

Remember the KISS principle:
Keep It Simple, Stupid! :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top