Compare 2 Tables Function -- identifies all value changes EXCEPT if value was = NULL (1 Viewer)

EEH_Help

Member
Local time
Today, 13:56
Joined
Feb 15, 2020
Messages
32
Experts:

I need some assistance with identifying a process flaw in an overall well-working function. Allow me to provide some background first.

Background:
- I need to compare two (2) tables: "Before" and "After".
- Initially, the "After" table is a replica of the "Before" table.
- At some point records will be updated only in the "After" table.
- Given that my actual tables may have 50+ fields and 20k plus records, I need to be able to readily identify what value was changed in the "After" table.

Attached are three (3) version of the same *sample* database. Please follow the steps as illustrated below:

Version_01:
===========
a. Open DB... in this version both tables "tbl_01_Before" and "tbl_02_After" are identical... that is, no changes have been applied to the "After" table.
b. Open form "F01_MainMenu" and click command button "View Log (Value Changes)".
c. Table "tbl_Log_ValueChanges" opens with zero (0) records.
d. Based c., this is the **correct** output given that both source tables are identifical.

Version_02:
===========
e. For testing purposes, I modified five (5) records in table [tbl_02_After]. To make it very obvious, I used 7-digit values (e.g., "1111111", "2222222", "3333333", "4444444", "5555555".
f. Open v02 and follow steps a:b.
h. Now, given the value changes, the log file shows those 5 records (incl. record ID, fieldname, before/after values).
i. AGAIN, this works great!!!

Now, the issue lies in version 03 (which is a copy of v02).

Version_03:
===========
j. Again, for testing purposes, I made two (2) additional changes to the table [tbl_02_After].
k. Specifically, I added values "88888888" in record ID #7 (field [INJ_INJURY_TYPE_TIER2_ID]) and "999999999" in record ID #15 (field [INJ_BODY_PART_TIER1_ID]).
l. Now, please note that in table [tbl_01_Before], the 'before' values for the "88888888" AND "999999999" were both = NULL.
m. So, since a value changed from NULL to something else, these two additional records should also be captured by the VBA function.
m. Unfortunately though, the log only shows the 5 records (version 2 change) but NOT those 2 records where value was previously = NULL.

My question:
How should the VBA be modified in module "modCompareTables" so that a value change from NULL to something else will also be displayed/updated in tbl_Log_ValueChanges.


P.S. Besides the 3 ACCDB versions, I have also included a PPT which illustrates the process for the 3 versions.

Thank you for your help in advance,
Tom
 

Attachments

  • Compare 2 Tables.zip
    307.3 KB · Views: 501

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:56
Joined
May 21, 2018
Messages
8,519
Code:
  If Nz(nField_Table1.Value, "") <> Nz(nField_Table2.Value, "") Then
                                'Creation of log table

tbl_Log_ValueChanges tbl_Log_ValueChanges

LOG_IDCHANGED_RECORD_IDFIELDNAMEVALUE_BEFOREVALUE_AFTER
1​
4​
INJ_BODY_PART_TIER2_ID8631111111
2​
7​
INJ_INJURY_TYPE_TIER2_ID88888888
3​
10​
INJ_INJURY_TYPE_TIER1_ID1202222222
4​
15​
INJ_BODY_PART_TIER1_ID999999999
5​
18​
INJ_BODY_PART_TIER1_ID153333333
6​
20​
INJ_INJURY_TYPE_TIER1_ID2554444444
7​
24​
INJ_INJURY_TYPE_TIER2_ID2825555555
 
Last edited:

EEH_Help

Member
Local time
Today, 13:56
Joined
Feb 15, 2020
Messages
32
MajP -- absolutely beautiful!!!!

Thousand thanks for helping me solve this!

Cheers,
Tom
 

EEH_Help

Member
Local time
Today, 13:56
Joined
Feb 15, 2020
Messages
32
Code:
  If Nz(nField_Table1.Value, "") <> Nz(nField_Table2.Value, "") Then
                                'Creation of log table

tbl_Log_ValueChanges tbl_Log_ValueChanges

LOG_IDCHANGED_RECORD_IDFIELDNAMEVALUE_BEFOREVALUE_AFTER
1​
4​
INJ_BODY_PART_TIER2_ID8631111111
2​
7​
INJ_INJURY_TYPE_TIER2_ID88888888
3​
10​
INJ_INJURY_TYPE_TIER1_ID1202222222
4​
15​
INJ_BODY_PART_TIER1_ID999999999
5​
18​
INJ_BODY_PART_TIER1_ID153333333
6​
20​
INJ_INJURY_TYPE_TIER1_ID2554444444
7​
24​
INJ_INJURY_TYPE_TIER2_ID2825555555
PERFECT SOLUTION!!!!
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 03:56
Joined
Jan 20, 2009
Messages
12,851
Your database shows signs of not being normalised such as repeating field names with numbered suffixes and fifty fields.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:56
Joined
Feb 19, 2013
Messages
16,601
OP is on another site which is where this came from, and has had an awful lot of detailed help.

Doesn't appear to appreciate that there is no order for changes to the same record unless relying on the autonumber ID so not sure what the benefit is. You can't say 'this is what the record looked like' on a certain date.
 

EEH_Help

Member
Local time
Today, 13:56
Joined
Feb 15, 2020
Messages
32
CJ - thank you for chiming in.

Ultimately I did not find a solution to the question on the other site.

Thus I was hopeful I might find an answer here. I apologize for not incl. the cross-reference to the other forum. I meant no harm by it.

BTW, there no need to compare records based on dates. I purposefully did not go into detail as the "compare" is due to snapshot.

The proposed inclusion of the Nz value addresses the underlying issue perfectly.

Thank you,
Tom
 

Minty

AWF VIP
Local time
Today, 18:56
Joined
Jul 26, 2013
Messages
10,367
As stated by @CJ_London the OP has had extensive, detailed and time-consuming assistance provided in numerous other threads over at https://www.accessforums.net/showthread.php?t=84088 and
https://www.accessforums.net/showthread.php?t=84040 and
https://www.accessforums.net/showthread.php?t=83995 as examples.

There seems to be an expectation that this type of development can be obtained gratis without much effort to develop a solution themselves, and then to jump ship when the answer isn't provided in a timely fashion.

The lack of any acknowledgement of this is quite a worrying trait.
 

Users who are viewing this thread

Top Bottom