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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adodb.recordset object ...er, how does it work? 2

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
Hello,

I want to do something fairly simple (I think) and populate a listview box on an access form with a selection of records from a single table. I thought the most sensible way to do this (other than some sort of convoluted loop involving multiple DLookup's) would be to return a recordset and then loop through that somehow.

I think I've figured out how to return the recordset;

Code:
    Set rstHistory = New ADODB.Recordset
    rstHistory.CursorLocation = adUseClient
    rstHistory.Open "Select updateDate, updateSource, updateDescription FROM History WHERE reqID = " & txtReqID.Value, _
    CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    Set Forms("Requirements_New").Recordset = rstHistory

(not sure if I need to assign the recordset to the form?)

However, I can't figure out how to loop through the recordset and pull out the data I want. What I want to do is something like;

Code:
    For Each objRecord in rstHistory
      strListItem = objRecord.FieldData(0) & ","
      strListItem = strListItem & objRecord.FieldData(1) & ","
      strListItem = strListItem & objRecord.FieldData(2)

      Listview.AddItem strListItem
    Next

...but that code's all just made up and recordsets, it seems, just don't work this way. The problem is that all the help files and guides I've found regarding recordset objects are either very vague or deal with far more complicated things I just don't want to do :(

...so, sorry that this is rather taking advantage of everybody's good nature here, but can anybody suggest a way I can do what I want to do? Alternatively, can anybody explain the basics of how to use recordset objects (or point me to a tutorial which is easy to follow?)

Thanks,

Paul
 
How about:
Code:
While Not rs.EOF ' the end of the recordset
strListItem = rs.Fields("FieldName") & ","
      strListItem = strListItem & rs.Fields("FieldName2") & ","
      strListItem = strListItem & rs.Fields("FieldName3")
rs.MoveNext ' move to the next record
Loop
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
That seems improbably sensible syntax - I'll give it a go, thanks :)

Paul
 
try this
me.Listview.recordset=rstHistory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top