Trigger to count child records linked to parent table then inserting value into parent table

StackOverflow https://stackoverflow.com/questions/22153071

سؤال

Parent (licenseID, countChilds)
Child (hostID, licenseID)

Trying to write an after insert/update/delete trigger that fires when adding a record to the child table. It needs to count child records linked to the parent and then insert this value into the parent.

But I keep getting the SQL statement is not valid.

So far I have this: enter image description here

I am using MS Access 2010.

هل كانت مفيدة؟

المحلول

I am fairly sure you can get away with DCount, for example, this works for me:

data macro

But I would still recommend not doing this and just getting your counts from a query.

نصائح أخرى

This seems to work, at least for After Insert:

AfterInsert.png

The After Update Data Macro would be a bit more involved because it might have to update two [License] records (one for [Host].[licenseID] and another for [Old].[licenseID]), or perhaps none (if [Host].[licenseID] did not change).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top