Update Data from one database in another one (1 Viewer)

Haakon

New member
Local time
Today, 20:21
Joined
Aug 2, 2013
Messages
7
Dear all,

As I stated already in another post:
I'm relatively new to MS Access (using MS Access 2013 but the db should work on 2010, too) and try to develop a database for an NGO I'm working in. [...].

However now I start to create forms and later reports for the actual user. The database will store information about clients and track consultations and assistance the NGO gives to them. There will be around 50.000 to 70.000 clients in the main table. Every client has a specific Individual ID and is member of a family which itself has another specific Group ID.
So now, I am almost done with forms (at least I want to believe that:D). But I ran into an issue I would love to have your comment and different approach on:

The Database I create is projected on another, significantly bigger database! The one I create is a kinda light version for other field offices with only the information they need to have, and additional tables for them to gather their own data and track their own activities. This being said, the light database needs to be updated every month once by the big (mother version). Both DBs cannot be connected!!!

So we will send to the field offices altogether 5 tables in one mdb-file every month. These 5 tables exist with the same structure ( name, field data-types, etc.) in the light version.

I now want to make an automatic update option (by pressing a key and select the "update-file"), i.e. based on the the respective Primary Key of every table the entry in the smaller DB should be updated!

Update for me means the following three things (Assume big DB is A, small DB is B):
1) If Primary Key (PK) exists in both tables of A and B, update the rest of the fields in B belonging to that key based on the specific record of A

2) If PK does not exist in A but in B, delete record from the database B (case: record was deleted in A after last update)

3) If PK does not exist in B but in A, add the record to database B (case: record was added to database A after last update)

I would like to show you what I already found in the internet on solving task 1) but I cannot post links due to my status :(
(One post from this form: "update one table using another" by kaiwalya1234;
And "Update Data by Using a Query" from the Access Help section of Microsoft)
Both links basically describe how to update one table by another in importing or linking the update-source table in the current DB, create a query with both tables, link the PKs of both and then using the Update To Criteria [UpdateSourceTable].[Field] for each field that I want to update.

But I wanted to ask before I implemented that if I should make a complete different approach since I also have 2) and 3) as tasks....

All insights, ideas, etc. are very very welcomed!!!! Just the actual way of updating the DB is not "discussable" :p

All the best,
Haakon
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:21
Joined
Feb 19, 2002
Messages
43,296
I'm getting the feeling that you are updating data in both places. How do you decide which takes precedence? You are talking only about presence or absence. What if a record gets updated in the main database and also in the remote database? Which update survives?
 

Haakon

New member
Local time
Today, 20:21
Joined
Aug 2, 2013
Messages
7
Hey Part Hartman,

thanks for your response first of all :)

No, the big database is the master-DB (A in my example) from which the updated data is retrieved. The light database (B) has these tables in common with A which cannot be altered within B. These tables and their fields can only be altered by database A..

However, in the light database there are a lot of other tables in relationship to these master-tables. these smaller tables contain information gathered which is not relevant for the big Master table but is used to track counselings, or other services. This data is used for the actual User to have a better understanding of the person he is looking up as well as creating monthly reports etc...

I hope it got a little bit clearer! So 5 tables of A are used to updated, delete, or add records to 5 tables in B...not the other way :)

Best,
Haakon
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:21
Joined
Feb 19, 2002
Messages
43,296
Rather than trying to update the slave tables, I would put them in a database by themselves and just replace it whenever updating is required. If you really want everything in the same database, then delete the tables and replace them. It will be simpler than trying to add/change/delete.
 

Haakon

New member
Local time
Today, 20:21
Joined
Aug 2, 2013
Messages
7
But don't I then have the problem, that I have lost data staying in the database, whenever I replace the full tables?
For example, we have two records in database B. After the replacement, however, we only have one of the two left. So the records in the other "counselling"-tables related to the now missing record have no connection anymore and stay as lost/unrelated data in the database...

I'm not sure if I could explain myself because I'm sick at the moment and my head is not working that well unfortunately :(

Is there not an option which goes like:
If record X from database A exists in B Then Update/Replace X and mark X as updated
If record X from database A does not exist in B then Add X and mark as added
Show all records in B which are not marked updated or added and delete these records
Unmark all records in B (so they are prepared for the next update)

Best,
Haakon
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:21
Joined
Feb 19, 2002
Messages
43,296
You said the big database is the master for these tables. Updating tables in multiple places is seriously difficult to manage and I recommend against it. Your method does not consider changes correctly. You are saying that if a record is changed in databaseB then it will be overlaid by whatever data comes in from databaseA.

There is not an option that goes .... You need to build it. It will take a couple of queries but is not complicated.

What is the purpose of including data from the master source? Typically when you do this, the data you bring down from the master is "lookup" stuff like Department names or code tables. Transaction records tend to be taken from the slave to the master for consolidation. Maybe I am misunderstanding your description of which way the data is moving.

In either case, if data is updated in multiple places, you need to have a way of determining which data should be kept. You can't just arbitrarily blow away data. There is no point in allowing the user to update it if you could overlay it without warning the next day. For starters, add a time stamp to each table. Then you can compare the values of the field to determine which is newer. You may be able to do this with queries but it might be better to write a VBA code loop.
 

Users who are viewing this thread

Top Bottom