Discussion Locked

Creating a Recordset Programmatically

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a quick question regarding creating a recdordset programmatically in Access 2000. I've been asked to generate a rollover function for existing records. The problem arises if the user creates a rollover (copying the current years recordset and adding a year to each date field). There may not be a complete recordset to work with. For example, each client has a Valuation that corresponds to Quarterly, Semi-Annual, and Annual. If only 2 of the quarterly records were entered, the rollover will only create 2 records for the new year. I need the new rollover function to read the base client info, check to see if it's Q, S-A, Or A, then create the appropriate number of records for the new year. Any ideas as to how this can be accomplished?

3 replies

by bob sellman

If I understand your requirements, you basically want to add a complete set of records to a table for a new year and the number of new records for each client will depend upon whether the client is Q, S-A, or A.

Here's the concept of how I would approach this, assuming that you will insert a new record to the table as needed. (You could test and even use a temporary table for creating the new records, then append the entire new table to the existing table.)

First, create a recordset froma query which lists all clients and all records for the current year. The relationship is all clients and any current year records, so that all clients are returned in the query, even if no records were entered for the current year for a client. Sort this recordset by client and date field.

Set variables for the client ID, the indicator (Q, S-A, A), the date, and a counter. Read each record. At the first record for a client, determine the number of records to add (4, 2 or 1), and check the date. If it's valid for the period, add a year, and insert a new record into the table with the appropriate data. If it's not the right period, insert a new record with the right date, then look at the current data again. If you're still not atthe right date, insert another new record with the right date. Keep looping until you reach data with the correct date for the period.

When the client ID changes, make sure you write any missing records before proceeding to process the new vendor.

What I'm talking about is basically a for to next loop within another for to next loop. The number of iterations of the inner loop will be controlled by the valuation (Q,S-A,A). You might need a flag so that if the inner loop goes to a new record that has a new vendor, the outer loop will not increment (or you just go back to an appropriate point in the inner loop).

Hope this helps.

by Member 36124717

Thanks Bob . . . I had to do some design changes (moving a field from one table to another), but that worked. Thanks again for the suggestion!

This discussion is closed to new replies.