Need to compare two access databases. Please guide on 1. how to use VBA to connect multiple database 2. how to dynamically choose which database to connect 3. how to find if match is unique / and if not insert result into different table 4. query to match
First Database (Actually set of database files of same type - date wise)
(Called Database 1 for easy understanding):
File Names are :
2013-03-01.mdb
2013-03-02.mdb
2013-03-03.mdb
Each file will have over a million records - Hence speedy comparison required.
Fields
ID RowInfo Description Value Region
Database 2 :
2013-03.mdb
Fields
Table 1 : InvoiceNumber Value CompanyName Date
Table 2 : InvoiceNumber Region
Table 3- Match Result:InvoiceNumber Value ID RowInfo Description CompanyName Date
Table 4- Match Result:InvoiceNumber Value ID RowInfo Description CompanyName Date
For each and every Invoice in Database2 , Look up in the database 1 (in the file specified in the Date Column). find coresponding match in Database1 based on Region and Value. In case Region not mentioned then only based on value. In case no match found , then check Date+1 file also. But must ensure unique match only. No Two InvoiceNumbers should match to the same ID (within same date) in Database1.
For each Invoice , if there is an unique match in DB1 , then insert result into Table 3 of DB2. If there is more than one match(more than one ID in DB1 for single Invoice) , then insert result into Table 4.