Error handle key violations

B

bumpmobile

Hello folks. I am running Acess 2003 at a therapeutic boarding school. I
have a form that therapists can use to select which diagnoses kids have. On
this form I have a button which runs an append query to add their selections
to a table, tblDiagnoses. I have the indexes in tblDiagnoses set so that one
kid cannot have the same diagnosis twice. I am absolutely sure one of the
therapists will try to do this though. I have tried to add error handling
but I still get the Index/Key Violation-Yes, No Cancel screen and never get
to the error handling (except in the case of a "cancel"). Is there any way to
make a key violation trigger an actual error? I have tried both:

docmd.OpenQuery "qryAppendDiagnosis", acViewNormal

as well as

docmd.RunSQL "SQL cut and pasted from SQL view of qryAppendDiagnosis"

Thanks in advance,

Adam
 
D

David C. Holley

Encapsulate the query in an IF DCount(fieldname, tableName,
wherestatement) = 0 THEN statement
If your *ABSOULTELY* certain that you'll never have a child with the
same DX (doc's kid).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top