Hi everyone,
We're using a Microsoft Access file to keep track of monthly salaries, and currently have 1 file that we've saved on the computer for each month in the past. Instead of copy/pasting the file for future months, we want to have an entire program with an archiving function. Basically my question is what should be taken into account in the design of the archiving function?
At the moment, we have four tables/queries that need to be copied.
1. A Taxes Table, containing the current month, and the level of taxes applied for each employee that month (a VBA function extracts the taxes percentages and uses them to calculate salaries for each employee)
2. A Salaries Query that has one record for each employee with their salaries, bonuses, taxes and everything else.
3. A Summary Query of the above mentioned Query (to summarise things like total salaries paid, total taxes paid by kind, etc.)
4. A Bonuses Table which can have multiple entries for each employee (the total bonus for each is added up and can be found in the Salaries Query)
Now I'm thinking to make 4 tables which will host all this information in an archive format, which have the same structure as the queries/tables they will be hosting with the addition of a date field for the respective month. These will be created using 4 Update Queries, which will be run every time the user wants to archive.
So these four tables will be as follows:
- A Past_Taxes table which holds 1 record for each time the archive program gets run containing the date of the month (DOM) + the 1 record contents of the Taxes Table
- A Past_Bonuses table which holds all the records of bonuses. Basically when the update query will be run, the records contained by the Bonuses Table will be pasted in here and a date added to all of them (the same as the previously mentioned DOM)
- A Past_Salaries Table which holds one record for each employee with the added DOM field for each.
- A Past_Summary_Salaries Table which holds 1 record for each DOM value summarising the data for each month.
Now the DOM value will be the indexing field for the Past_Taxes table, and for the Past_Summary_Salaries Table but not in the other two (since there will be more than 1 record with the same DOM value). So when I make the macro to run the 4 update queries a possible problem will arise if the user accidentally hits the update button twice, etc. When the macro will run the update query for the Past_Taxes table, and for the Past_Summary_Salaries_Table it will fail - so no records will be added (because there already is a record there with the specific DOM value). However - the update query will work for the Past_Salaries Table and for the Past_Bonuses table (these two tables have a Many-to-One relationship with the Past_Taxes and Past_Summary_Salaries Tables). Is there any way to prevent the macro from running further if the first two update queries fail? If so, how? If I can prevent that, then no errors could lead to corruption of the data.
After that it seems quite straight-forward, we can apply filters by the date to extract the month(s) we're interested in from the database. So what do you think? Is there a better way to design this? And how should the macro-issue be solved? Thanks!