G
Gary Schuldt
I have a table tblT that's updated by a single form frmT.
tblT has an autonumber primary key TID
However, there is another uniqueness constraint dictated by the business,
and that is that no two records in tblT should have the same value for the
combination of 3 fields--txtA, txtB, and txtC (txtA & txtB & txtC).
txtA is the only field in this trio requiring a value; the other two can be
valued or not, independently.
I'd like to be able to at least warn the user when they're about to create a
violation of this business rule. Here's my idea:
1. Create a BeforeUpdate event for frmT
2. Run a Select query with criteria that txtA, txtB and txtC from the form
equal that in the database, and also include TID in the query. Use the
Top=1 option.
3. (Maybe I need to open a form based on the above query so I can tell the
user the TID of the duplicate record?)
4. If there are no records in the result set, everything is OK.
5. If there is a record in the result set (there shouldn't be more than
one, anyway), tell the user the one in the frmT duplicates another one, and
here's the TID of the other one, and they should fix the problem . . .
something like that.
Questions:
A. Is this approach a good one to achieve my end of preventing violations
of the uniqueness constraint? If not, what would be better?
B. Can anyone point me to some standard code?
Thanks.
Gary
tblT has an autonumber primary key TID
However, there is another uniqueness constraint dictated by the business,
and that is that no two records in tblT should have the same value for the
combination of 3 fields--txtA, txtB, and txtC (txtA & txtB & txtC).
txtA is the only field in this trio requiring a value; the other two can be
valued or not, independently.
I'd like to be able to at least warn the user when they're about to create a
violation of this business rule. Here's my idea:
1. Create a BeforeUpdate event for frmT
2. Run a Select query with criteria that txtA, txtB and txtC from the form
equal that in the database, and also include TID in the query. Use the
Top=1 option.
3. (Maybe I need to open a form based on the above query so I can tell the
user the TID of the duplicate record?)
4. If there are no records in the result set, everything is OK.
5. If there is a record in the result set (there shouldn't be more than
one, anyway), tell the user the one in the frmT duplicates another one, and
here's the TID of the other one, and they should fix the problem . . .
something like that.
Questions:
A. Is this approach a good one to achieve my end of preventing violations
of the uniqueness constraint? If not, what would be better?
B. Can anyone point me to some standard code?
Thanks.
Gary