#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    144
    Rep Power
    8

    Access items in a RecordSet


    Hi,

    I have a recordset from data pulled in from SQL Server. I'm wondering how I can access specific items in that recordset?

    I printed rst.RecordCount and I see there are 9 records. However, if I try to access anything larger than rst.fields(0), for example, rst.fields(1), it gives me an error saying that item is not found in this collection. How would I access the other 8 items? Thanks
    Cheers,
    Fred Liu
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    There are nine records but how many fields?

    rst.movenext gets you to the next record

    .fields(n) refers to the nth field of the current record

    So basically

    Code:
    Do Until rst.EOF
       MsgBox rst.fields(0)
       rst.MoveNext
    Loop
    You can also refer to the fields like rst![FieldName]
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    8
    Rep Power
    0

    How to access items of recordset


    Dim ZdrojSQL As DAO.Recordset
    Dim WantedData as Whatever
    Dim i as Integer

    Set ZdrojSQL = CurrentDb.OpenRecordset("SELECT * FROM SeznamTemp")

    Do Until rs.EOF
    i=i+1
    If i=15 Then
    WantedData=rs(7)
    Exit Do
    EndIf
    rs.MoveNext
    Loop

    rs.Close
    Set rs=Nothing

IMN logo majestic logo threadwatch logo seochat tools logo