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..
---------------------------------------------------
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'
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!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.