Link to home
Start Free TrialLog in
Avatar of NJPhillips

asked on

Add data from recordset to array and sort by date

I have a recordset, "rsTaskinfo" which has a field titled "StatusDateTime" which lists the date/time stamp a person updated their status. What I would like to do is find the last entry entry.... the kicker, is the recordset is already sorted by a persons name, otherwise it would be easy.

My thoughts were to add all of the records to an array and sort that way... but I am not sure if that is very efficient.

What say you experts?
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NJPhillips


Your solution is do-able, and was my first thought... I was just hoping to minimize trips to the DB is possible... however, it might really be more efficient to do that.

There is a more efficient way as far as the database to throw it into an array but the trade off is a little more complex code.  

Do you have 100,000's rows in the database?  Do you have 100's of people per minute accessing database? Does the query contain a lot of wild card searches?    I think what is "better" is personal preference and use.  If the actual usage is small, I think it is easier to go with the simple code.  

Without knowing what datafields you need it is hard to give you that option.  In short, you would create a dynamic array.

' open rs
    Dim demoArray()
    Dim counter
     counter = 0
    do until rs.eof
        ReDim Preserve demoArray(i)
        DemoArray(counter) = rs.field
       if not rs.eof then
          counter = counter +1
      end if
'close rs
' now that you have your array, create a function to check the array with each row of data in your display

Function  functionName( checkID)
      matchID = 0
     for each x in demoArray
         if x = checkID then
            macthID = checkID
        end if
end function
' the returned matchID can then be used to mark the record with the last update