Avoid duplicate records on insert

I have a People table with just the fields: ID | Name 

I also have an ActivitiesEnrolments table with the fields: ID | Activity ID | Person ID

Finally, I have Activities with: ID | Name

Note that People has a column called "Related ActivitiesEnrolments" with the usual REF_ROWS("ActivitiesEnrolments", "Person ID")

All I want to do is make sure that ActivitiesEnrolments is NOT added the same Activity. So, when adding a new enrolment, I want the select box for the activity NOT to display the activities the user is already enrolled in.

My idea was to edit the column Activity ID in ActivityEnrolments, and have this in Valid If:

 

ISBLANK(
  SELECT(
    [Person ID].[Related ActivitiesEnrolments][_ROWNUMBER],
    [Activity ID] = [_THISROW].[Activity ID]
  )
)

However, I am not having much luck. I want to keep performance right. So, I want to select the ActivitiesEnrolments for that user, and check if the activity is already attached to that user.

But... what am I doing wrong?

 

ISBLANK(
SELECT(
[Person ID].[Related ActivitiesEnrolments][_rownumber],
[Activity ID] = [_THISROW].[Activity ID]
)
)

0 7 204
7 REPLIES 7
Top Labels in this Space