centralmike
asked on
Comparing two access results against each other
I have two access tables I am trying to compare against each other. The main table is the true source. The input table is a table a receive from a third party. The relationship between the two tables are the following fields:
AR_POL_ACCT_NUM
CO_CMPY_CDE
This makes the record unique. The problem I having i dont know how to create the comparison query in my access basic module to update the tbl_output when the records don't match. I have deleted 25 records from tbl_input and change 5 others. So when complete tbl_output should at least have 30 records in it. So I know my third query needs to some type of outer join between tbl_main and and tbl_input. Thats what I need help building in my access module. I am attaching the database with tables and modules.
ComparisonTesting.accdb
AR_POL_ACCT_NUM
CO_CMPY_CDE
This makes the record unique. The problem I having i dont know how to create the comparison query in my access basic module to update the tbl_output when the records don't match. I have deleted 25 records from tbl_input and change 5 others. So when complete tbl_output should at least have 30 records in it. So I know my third query needs to some type of outer join between tbl_main and and tbl_input. Thats what I need help building in my access module. I am attaching the database with tables and modules.
ComparisonTesting.accdb
To get the changes, you will need to add a field ModifyTimeStamp, and it should be updated after each change on this record, then you can match the tables by if timestamp is different.
ASKER
I get the outer join query statement. But i need this in the access module. Also I am not getting the 5 rows that don't match. Its not update query. It's a query that is comparing recordsets to each other. I need the records that dont match from tbl_main inserted into the tbl_output table.
I added them in the module
ComparisonTesting.accdb
ComparisonTesting.accdb
ASKER
I think we are almost there. Just a couple of questions. Can we not update table tbl_output in the code module I will need to create a report of this table after the comparison is complete? Second questions in the record change query in the module you have a join on AO2_ADMIN_SYS_CDE. The only two columns that want change are AR_POL_ACCT_NUM and CO_CMPY_CDE, so can we eleminate there where statement. Two queries return the correct results I am looking for.
1) Why not making a report on the tbl_output.
2) The Join on AO2_ADMIN_SYS_CDE in the Where statement is to check if they are different.
2) The Join on AO2_ADMIN_SYS_CDE in the Where statement is to check if they are different.
ASKER
Question 1 tbl_Output never gets updated in the module
Question 2 - Should I add the other columns in the where statement that can change.
example
"WHERE ((([tbl_Main_orig]![AO2_AD MIN_SYS_CD E]=[tbl_In put]![AO2_ ADMIN_SYS_ CDE])=Fals e));")
[tbl_main rst2]![SI_PRODUCTION_NUM] =[tbl_Input]![SI_PRODUCTIO N_NUM])=Fa lse
[tbl_main rst2]![AO2_ADMIN_SYS_CDE] = [tbl_Input]![AO2_ADMIN_SYS _CDE])=Fal se
[tbl_main rst2]![AO2_OPERATOR_ID] = [tbl_Input]![AO2_OPERATOR_ ID])=False
[tbl_main rst2]![AO2_CURR_TME_STAMP] = [tbl_Input]![AO2_CURR_TME_ STAMP])=Fa lse
[tbl_main rst2]![AO2_SPLIT_PCT] = [tbl_Input]![AO2_SPLIT_PCT ])=False
[tbl_main rst2]![FP9_ASGN_NUM] = [tbl_Input]![FP9_ASGN_NUM) =False
Question 2 - Should I add the other columns in the where statement that can change.
example
"WHERE ((([tbl_Main_orig]![AO2_AD
[tbl_main rst2]![SI_PRODUCTION_NUM] =[tbl_Input]![SI_PRODUCTIO
[tbl_main rst2]![AO2_ADMIN_SYS_CDE] = [tbl_Input]![AO2_ADMIN_SYS
[tbl_main rst2]![AO2_OPERATOR_ID] = [tbl_Input]![AO2_OPERATOR_
[tbl_main rst2]![AO2_CURR_TME_STAMP]
[tbl_main rst2]![AO2_SPLIT_PCT] = [tbl_Input]![AO2_SPLIT_PCT
[tbl_main rst2]![FP9_ASGN_NUM] = [tbl_Input]![FP9_ASGN_NUM)
Answer 1 - I update the module it should add new records in tbl_Output
Answer 2 - you can add to the Where statement all fields that can be changeable, with the OR statement:
Answer 2 - you can add to the Where statement all fields that can be changeable, with the OR statement:
SELECT tbl_Main_orig.*
FROM tbl_Input INNER JOIN tbl_Main_orig ON (tbl_Input.SI_PRODUCTION_NUM = tbl_Main_orig.SI_PRODUCTION_NUM) AND (tbl_Input.AR_POL_ACCT_NUM = tbl_Main_orig.AR_POL_ACCT_NUM) AND (tbl_Input.CO_CMPY_CDE = tbl_Main_orig.CO_CMPY_CDE)
WHERE ((([tbl_Main_orig]![AO2_ADMIN_SYS_CDE]=[tbl_Input]![AO2_ADMIN_SYS_CDE])=False))
OR ((([tbl_Main_orig]![SI_PRODUCTION_NUM]=[tbl_Input]![SI_PRODUCTION_NUM])=False));
I forgot to add the file
ComparisonTesting.accdb
ComparisonTesting.accdb
ASKER
I would have expected table tbl_Output to have 31 records when the module complete. It looks like the "delete statement might be in the wrong place. We have 26 new records and 5 change records. When you run the module you only get 27 records. Also I couldn't get the "Or" statement to work with the additional fields.
i see in your data few dublex AR_POL_ACCT_NUM, like
BC7009106
BC7009110
BC7009122
BC7000028
so from 31 you will only get 27 records.
Your tables should have a unique number.
BC7009106
BC7009110
BC7009122
BC7000028
so from 31 you will only get 27 records.
Your tables should have a unique number.
What's was your problem with the OR statement
SELECT tbl_Main_orig.*
FROM tbl_Input INNER JOIN tbl_Main_orig ON (tbl_Input.SI_PRODUCTION_NUM = tbl_Main_orig.SI_PRODUCTION_NUM) AND (tbl_Input.AR_POL_ACCT_NUM = tbl_Main_orig.AR_POL_ACCT_NUM) AND (tbl_Input.CO_CMPY_CDE = tbl_Main_orig.CO_CMPY_CDE)
WHERE ((([tbl_Main_orig]![AO2_ADMIN_SYS_CDE]=[tbl_Input]![AO2_ADMIN_SYS_CDE])=False))
OR ((([tbl_Main_orig]![SI_PRODUCTION_NUM]=[tbl_Input]![SI_PRODUCTION_NUM])=False))
OR ((([tbl_Main_orig]![AO2_ADMIN_SYS_CDE]=[tbl_Input]![AO2_ADMIN_SYS_CDE])=False))
OR ((([tbl_Main_orig]![AO2_OPERATOR_ID]=[tbl_Input]![AO2_OPERATOR_ID])=False))
OR ((([tbl_Main_orig]![AO2_CURR_TME_STAMP]=[tbl_Input]![AO2_CURR_TME_STAMP])=False))
OR ((([tbl_Main_orig]![AO2_SPLIT_PCT]=[tbl_Input]![AO2_SPLIT_PCT])=False))
OR ((([tbl_Main_orig]![FP9_ASGN_NUM]=[tbl_Input]![FP9_ASGN_NUM])=False));
ASKER
when i put your code in record change statement. All the lines turn red. I tried putting in a continuation line _ and the code remains red.
here is the code
rst.Close
'Records Changed
Set rst = CurrentDb.OpenRecordset("S ELECT tbl_Main_orig.* " & _
"FROM tbl_Input INNER JOIN tbl_Main_orig ON (tbl_Input.SI_PRODUCTION_N UM = tbl_Main_orig.SI_PRODUCTIO N_NUM) AND (tbl_Input.AR_POL_ACCT_NUM = tbl_Main_orig.AR_POL_ACCT_ NUM) AND (tbl_Input.CO_CMPY_CDE = tbl_Main_orig.CO_CMPY_CDE) " & _
WHERE ((([tbl_Main_orig]![AO2_AD MIN_SYS_CD E]=[tbl_In put]![AO2_ ADMIN_SYS_ CDE])= False)) _
OR ((([tbl_Main_orig]![SI_PRO DUCTION_NU M]=[tbl_In put]![SI_P RODUCTION_ NUM])= False)) _
OR ((([tbl_Main_orig]![AO2_AD MIN_SYS_CD E]=[tbl_In put]![AO2_ ADMIN_SYS_ CDE])= False)) _
OR ((([tbl_Main_orig]![AO2_OP ERATOR_ID] =[tbl_Inpu t]![AO2_OP ERATOR_ID] )= False)) _
OR ((([tbl_Main_orig]![AO2_CU RR_TME_STA MP]=[tbl_I nput]![AO2 _CURR_TME_ STAMP])= False)) _
OR ((([tbl_Main_orig]![AO2_SP LIT_PCT]=[ tbl_Input] ![AO2_SPLI T_PCT])= False)) _
OR ((([tbl_Main_orig]![FP9_AS GN_NUM]=[t bl_Input]! [FP9_ASGN_ NUM])= False));
here is the code
rst.Close
'Records Changed
Set rst = CurrentDb.OpenRecordset("S
"FROM tbl_Input INNER JOIN tbl_Main_orig ON (tbl_Input.SI_PRODUCTION_N
WHERE ((([tbl_Main_orig]![AO2_AD
OR ((([tbl_Main_orig]![SI_PRO
OR ((([tbl_Main_orig]![AO2_AD
OR ((([tbl_Main_orig]![AO2_OP
OR ((([tbl_Main_orig]![AO2_CU
OR ((([tbl_Main_orig]![AO2_SP
OR ((([tbl_Main_orig]![FP9_AS
'Records Changed
Set rst = CurrentDb.OpenRecordset("SELECT tbl_Main_orig.* " & _
"FROM tbl_Input INNER JOIN tbl_Main_orig ON (tbl_Input.SI_PRODUCTION_NUM = tbl_Main_orig.SI_PRODUCTION_NUM) AND (tbl_Input.AR_POL_ACCT_NUM = tbl_Main_orig.AR_POL_ACCT_NUM) AND (tbl_Input.CO_CMPY_CDE = tbl_Main_orig.CO_CMPY_CDE) " & _
"WHERE ((([tbl_Main_orig]![AO2_ADMIN_SYS_CDE]=[tbl_Input]![AO2_ADMIN_SYS_CDE])=False)) " & _
"OR ((([tbl_Main_orig]![SI_PRODUCTION_NUM]=[tbl_Input]![SI_PRODUCTION_NUM])=False)) " & _
"OR ((([tbl_Main_orig]![AO2_ADMIN_SYS_CDE]=[tbl_Input]![AO2_ADMIN_SYS_CDE])=False)) " & _
"OR ((([tbl_Main_orig]![AO2_OPERATOR_ID]=[tbl_Input]![AO2_OPERATOR_ID])=False)) " & _
"OR ((([tbl_Main_orig]![AO2_CURR_TME_STAMP]=[tbl_Input]![AO2_CURR_TME_STAMP])=False)) " & _
"OR ((([tbl_Main_orig]![AO2_SPLIT_PCT]=[tbl_Input]![AO2_SPLIT_PCT])=False)) " & _
"OR ((([tbl_Main_orig]![FP9_ASGN_NUM]=[tbl_Input]![FP9_ASGN_NUM])=False));")
If you are interested in a commercial solution, our Total Access Detective product compares any two Access databases or two objects in one database for differences. This includes differences in records between tables where keyed fields identify records to compare.
In your case. if you make the two fields that are unique values your primary key, the two tables can be compared for differences. Total Access Detective also offers a feature to combine the differences between two tables into a new table. All without having to write any code or queries: http://www.fmsinc.com/MicrosoftAccess/difference/data/combine-tables.asp
Hope this helps.
In your case. if you make the two fields that are unique values your primary key, the two tables can be compared for differences. Total Access Detective also offers a feature to combine the differences between two tables into a new table. All without having to write any code or queries: http://www.fmsinc.com/MicrosoftAccess/difference/data/combine-tables.asp
Hope this helps.
ASKER
one final question for you. What happens when you have no new records or no records that change? I get a error code 3021. I am not sure how to put error code checking in the module. if you can add that final piece to the module or tell me how to put in that error code handlings. I am attaching the database with a lot of changes. But the module that needs the error code is mod_KBMG_Staging
KBMG-RELATIONSHIP-STAGING.accdb
KBMG-RELATIONSHIP-STAGING.accdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all your help. I am kinda new to coding in access basic and this gave me a better understanding of the language.
Open in new window