View Full Version : Dynamically update field of a current record based on previous record


MRDIRK
04-30-2007, 05:16 PM
I need a way to dynamically store a particular value in "field_2" of the CURRENT record depending on whether or not the value of "field_1" of the CURRENT record is identical to the value of "field_1" of the PREVIOUS record within the same table. The table is sorted on "field_1".

So, if the value of "field_1" in the CURRENT record is "ABC" and the value of "field_1" in the PREVIOUS record is also "ABC", then store a value of "PPP" in "field_2" of the current record. IF on the other hand, the value of "field_1" in the CURRENT record is "ABC" and the value of "field_1" in the PREVIOUS record is "XYZ", then store a value of "WWW" in "field_2" of the current record.

I have a report that will use these results to count only the number of records that have a "WWW" in "field_2".

Is this doable, maybe in a query somehow?

I should add that whatever the solution, it needs to be compatible with Access 2000.

gemma-the-husky
05-01-2007, 05:04 AM
the trouble is, is that access has no real logical concept of a previous or next record in these terms - eg in your situation what happens if you insert a record in between the two matching records. An access table is really of collection of similar items - hence the normalisation process

however, practically, I presume there is some other reason for holding the duplicated/copy records. So when you enter a record, you could check for the existence of a match, and react appropriately. Checking afterwards probably requires some sort of recordset navigation, but bear in mind that access can have no idea of which record you record as the first record, and which is the second

on the other hand it may be that you really need a second table to store the possible instances of field_2 values, which would mean you need to reassess your data design.