Question : Access VBA Expert needed - bookmarks amongst 2 recordsets, etc

Hi -

  I need an Access VBA expert.

  I'm a fairly experienced access developer, but I am stumped.

  I need to select some data and I don't know how to do it efficiently

  I need data within a daterange, plus the previous record before that.

  Here's an example:

   Say I'm selecting a bunch of invoices
   Select * from invoices where date >= #1/1/2005 and date < 2/1/2005

   I'm going to loop through the invoices, looking for differences between them
   ie...
   lastshippingmethod = invoicesrecordset![shippingmethod]
   invoicerecordset.movenext
   do until invoicerecordset.eof
      if lastshippingmethod <> invoicerecordset![shippingmethod] then
           msgbox("this is a difference I am looking for"
     end if
   loop

   The problem is, for the given date range, I need to also do this comparison for the very first record returned
   I can't just increase the date range by a day - there might not be a record in that timeframe.

   Here's my crazy thoughts:
    Can I open a recordset of the whole table in parallel with the invoicerecordset, and use book marks to synch the records, then use the findprevious command on the other recordset?

    maybe like this?
    allinvoicesRS = Select * from invoices order by date
    invoicerecordset = Select * from invoices where date >= #1/1/2005 and date < 2/1/2005
 
  '(This next line I am completely making up - I have no idea of the proper syntax to use here)
   allinvoicesRS.bookmark = invoicerecordset.current record  
   allinvoicesRS.Findprevious('[customerid]=" & invoicerecordset![CustomerID])
   lastshippingmethod = allinvoicesRS![shippingmethod]
 
   do until invoicerecordset.eof
      if lastshippingmethod <> invoicerecordset![shippingmethod] then
           msgbox("this is a difference I am looking for"
     end if
   loop

 Is the above possible? would it work?

  Also I'd like to know if this can be done in memory with an array? (I'll post that as another question to keep points fair)

   

Answer : Access VBA Expert needed - bookmarks amongst 2 recordsets, etc

You will not be able to use bookmarks arcoss seperate recordsets. That being said, if you grab enough records to make sure you have, at least, the last previous entry you could use bookmarks to move back and forth within the same recordset ...  order the recordset desc by date and odometer, use TOP X ... make X be a large enough number so you will always be OK, better yet test the "last" record that comes back from the recordset to see if it is the same date as the "first" record and then double the value of X and open the recordset again if you did not get enough data. Now move backwards through the recordset to do you comparisons and you know you have the *last* date's record when it does not match the date of the previous record you looked at. Ack ... this makes perfect sense to me, I only hope it came across OK in this post.

Steve
Random Solutions  
 
programming4us programming4us