A
aacadprogrmr via AccessMonster.com
Let me see if I can describe the situation I have..
One table. No Primary Keys. (inherited code, gotta love it)
I want to compare records,
if the first field in record one matches the first field in record 2, then
make double sure the last field does NOT match (report error if so) then
'merge these records together by summing field 2(no others) and saving
rec2s field 6 along with the
'entire record 2 (maybe back in the same table??). How I get there is not a
big deal, I may have the wrong approach.
'Here is the data before.
example: Name them field 1 through 10 for this example.
65 1 1 2 2 4594
66 1 1 2 2 4506
66 1 1 2 2 4500
67 2 2 2 2 4511
68 2 2 2 2 4511
68 2 2 2 2 4500
68 3 2 2 2 4508
Here is the data after the function
65 1 1 2 2 4594
66 2 1 2 2 4506 4500
67 2 2 2 2 4511
68 7 2 2 2 4511 4500 4508
Here is the pseudo codeish I have written while thinking hope it helps.
'open rs in db (rs)
do while not eof
initialize empty temp array(ta)
get a record from table save to temparray
get second line from table
if ta.1 = rs.1 then
if ta.6 <> rs.6 then
if isnull(rs.7) then
(rs.2 = ta.2 + rs.2) and ta.6 goesinto rs.7
remove the first of the two records from the table (like by its index??)
elseif isnull(rs.8) then
(rs.2 = ta.2 + rs.2) and ta.6 goesinto rs.8
remove the first of the two records from the table (like by its index??)
else
'both are empty write error to complain and exit
endif
else if
'these should match write error to complain and exit
else 'the first fields do not match, all is good.
loop
cleanup/housekeeping then exit
***Before you roll on the floor laughing at this, I do not write in VBA, I
tend to lean towards C for AutoCAD instead but someone moved the cheese.
I am hoping advancing to the next record at the top of the loop will "save"
my changes and free up my array for more info. I know this stinks there are
holes all in it.
sorry
Thanks in advance!!!
One table. No Primary Keys. (inherited code, gotta love it)
I want to compare records,
if the first field in record one matches the first field in record 2, then
make double sure the last field does NOT match (report error if so) then
'merge these records together by summing field 2(no others) and saving
rec2s field 6 along with the
'entire record 2 (maybe back in the same table??). How I get there is not a
big deal, I may have the wrong approach.
'Here is the data before.
example: Name them field 1 through 10 for this example.
65 1 1 2 2 4594
66 1 1 2 2 4506
66 1 1 2 2 4500
67 2 2 2 2 4511
68 2 2 2 2 4511
68 2 2 2 2 4500
68 3 2 2 2 4508
Here is the data after the function
65 1 1 2 2 4594
66 2 1 2 2 4506 4500
67 2 2 2 2 4511
68 7 2 2 2 4511 4500 4508
Here is the pseudo codeish I have written while thinking hope it helps.
'open rs in db (rs)
do while not eof
initialize empty temp array(ta)
get a record from table save to temparray
get second line from table
if ta.1 = rs.1 then
if ta.6 <> rs.6 then
if isnull(rs.7) then
(rs.2 = ta.2 + rs.2) and ta.6 goesinto rs.7
remove the first of the two records from the table (like by its index??)
elseif isnull(rs.8) then
(rs.2 = ta.2 + rs.2) and ta.6 goesinto rs.8
remove the first of the two records from the table (like by its index??)
else
'both are empty write error to complain and exit
endif
else if
'these should match write error to complain and exit
else 'the first fields do not match, all is good.
loop
cleanup/housekeeping then exit
***Before you roll on the floor laughing at this, I do not write in VBA, I
tend to lean towards C for AutoCAD instead but someone moved the cheese.
I am hoping advancing to the next record at the top of the loop will "save"
my changes and free up my array for more info. I know this stinks there are
holes all in it.
sorry
Thanks in advance!!!