I cannot seem to figure out the best way to identify whether my record table already has the unique 3-column combination of the data using VBA.
My table is as follows:
CREATE TABLE sometable(
col1 NUMERIC,
col2 NUMERIC,
col3 NUMERIC,
col4 NUMERIC,
Primary Key(col1, col2, col3)
);
Now in my form I'm adding values into the table (ie. user fills up 3 fields, clicks an add
button and it inserts to the table).
If row of data is already there, pressing the add
button does nothing.
What I want to achieve is to check (using VBA) whether such row already exists (based on the uniqueness of col1 & col2 and col3) SUM up the col4 of an already existing record with the new addition.
For example if my already existing data is something like:
col1 col2 col3 col4
1 2 3 10
1 3 3 20
and user wants to add:
1 1 1 10
It would simply add a new row to the table. However, if he wants to add:
1 2 3 10
It would result in table:
col1 col2 col3 col4
1 2 3 20 'added up col4 here
1 3 3 20
1 1 1 10
The reason why I don't want to have an Auto-ID incrementing as col0 is because I would have to check the values in col1, col2 and col3 anyway to determine whether the new data should be added or simply re-calculated.