Results 1 to 3 of 3

Thread: Recordsets vs Collections vs Arrays

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    San Jose, Ca. - USA
    Posts
    302

    Recordsets vs Collections vs Arrays

    I've been using collections for quick lookups...
    it'll be easier if I show you through code instead of explaining too much.

    I do:
    option explicit
    dim db as dao.database
    dim rs as dao.recordset
    dim colIds as Collection
    dim fldTemp as Dao.Field

    Private Sub Something
    set colIds = New Collection
    set rs = db.querydefs("qryName").openrecordset(dbopenforwardonly)
    if rs.eof = true then
    else
    set fldtemp = rs.fields("fldName")
    do until rs.eof = true
    colIds.additem fldTemp.value
    rs.movenext
    loop
    rs.close
    set fldtemp = nothing
    endif
    set rs = nothing
    end sub

    The field is of LongInteger datatype. I use the collection to query other records by their ID in the table. This works pretty well for me, but this is only good if the collection stays small because collections use variants.

    So I was wondering if making another recordset object that is not attached to a database, with one LongInteger field would be a more viable than using a collection?

    Also what if the field in tha database was Date and not a LongInteger, Dates take a lot more space (I think). Should I just stick with a collection then?

    I thought about using a one dimensial Array but I dont know enough about them.

    Any thoughts on what would be faster, and which will take less space in memory?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2001
    Location
    San Jose, Ca. - USA
    Posts
    302

    bump

    hope nobody minds that i bump this

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Since are already went to the database and retrieved all the records (at least for that field) then it'd be easier to just use the filter method. I'm not sure if DAO has the filter method I think it does though. SIDE NOTE: DAO is of the devil, by-the-way. The filter method applies a sort of sub select query to the contents of a recordset.

    VB Code:
    1. rs.Filter="fldName=" & fldValue
    2. 'now the recordset is filtered to contain only the records that match the criteria.
    3.  
    4. 'to remove the filter
    5. rs.Filter=""
    6. 'now it has all the contents again

    You can also use Like or whatever you need to deal with other datatypes. Also you would set the connection to nothing to disconnect the recordset in ADO.

    What is it that you need to quick look up? Why is this list needed?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width