Hello -
I have many activities that are related to one company.
I have many contacts related to one activity via a simple join table called t_RelatedContac ts that holds the Activity_ID and the Contact_ID.
If a user decides to change the the company that the activities are related to, we need to delete any related contacts that may have been added for that activity as only contacts from the related company would be valid.
I have the following Event Procedure to delete records in the t_RelatedContac ts table when the Company ID field on my form changes.
-------------
-------------
The event does not run when the value in the Company_ID field is updated after a new company in selected. However, it runs perfectly if I manually change the value in the Company_ID field.
Any ideas greatly appreciated.
Many thanks
Sandra
[imgnothumb]http://bytes.com/attachments/attachment/5840d1324331290/12-19-2011-4-44-55-pm.jpg[/imgnothumb]
I have many activities that are related to one company.
I have many contacts related to one activity via a simple join table called t_RelatedContac ts that holds the Activity_ID and the Contact_ID.
If a user decides to change the the company that the activities are related to, we need to delete any related contacts that may have been added for that activity as only contacts from the related company would be valid.
I have the following Event Procedure to delete records in the t_RelatedContac ts table when the Company ID field on my form changes.
-------------
Code:
Private Sub Company_ID_AfterUpdate()
Dim strSQL As String
Dim Activity_ID As Integer
DoCmd.SetWarnings False ' to prevent confirmation of record delete
Activity_ID = Me.Activity_ID.Value
strSQL = "DELETE t_RelatedContacts.* FROM t_RelatedContacts WHERE (((t_RelatedContacts.Activity_ID)= " & Activity_ID & " ));"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
DoCmd.RunCommand acCmdRefresh
End Sub
The event does not run when the value in the Company_ID field is updated after a new company in selected. However, it runs perfectly if I manually change the value in the Company_ID field.
Any ideas greatly appreciated.
Many thanks
Sandra
[imgnothumb]http://bytes.com/attachments/attachment/5840d1324331290/12-19-2011-4-44-55-pm.jpg[/imgnothumb]
Comment