alpinegroove
Registered User.
- Local time
- Today, 15:17
- Joined
- May 4, 2011
- Messages
- 55
I posted this in a couple other places but haven't been able to resolve it.
I am not sure if I need an update query, VBA code, or a combination of both.
I use a form (linked to tblCourses) and a subform (linked to the junction table tblCoursePeopleRoles).
I am trying to update the field CourseHasTA2 in tblCourses when fkRoleID in the junction table equals 3. If fkRoleID=3, update CourseHasTA2 to "-1," else update it to "0."
I came up with the following After Update code for the combo box used to select the role in the subform / junction table:
But this has one major limitation: if Role 3 is selected last (after all the other roles had been designated), everything is fine. But since different people can have different roles in the same course, if a different role is selected in the form after Role 3, the flag reverts back to "0."
So this method doesn't achieve the goal if Role 3 is not the last one to be assigned, so I am thinking that either the code needs to be changed or that perhaps this should be some kind of query that looks at the junction table, but I am running into the same problem: The query first changes the flag to "-1" when it finds Role 3 but then when it continues to work, it also find a different role for the same course, and changes the flag back to "0."
Does anyone have any suggestions for how to handle this?
Sorry for the long explanation. I hope this makes sense. Thank you.
I am not sure if I need an update query, VBA code, or a combination of both.
I use a form (linked to tblCourses) and a subform (linked to the junction table tblCoursePeopleRoles).
I am trying to update the field CourseHasTA2 in tblCourses when fkRoleID in the junction table equals 3. If fkRoleID=3, update CourseHasTA2 to "-1," else update it to "0."
I came up with the following After Update code for the combo box used to select the role in the subform / junction table:
Code:
DoCmd.RunSQL "UPDATE tblCoursePeopleRoles LEFT JOIN tblCourses ON tblCoursePeopleRoles.CourseIDFK = tblCourses.CourseID SET tblCourses.CourseHasTA2 = IIf([tblCoursePeopleRoles].[RoleIDFK]=3,-1,0)"
But this has one major limitation: if Role 3 is selected last (after all the other roles had been designated), everything is fine. But since different people can have different roles in the same course, if a different role is selected in the form after Role 3, the flag reverts back to "0."
So this method doesn't achieve the goal if Role 3 is not the last one to be assigned, so I am thinking that either the code needs to be changed or that perhaps this should be some kind of query that looks at the junction table, but I am running into the same problem: The query first changes the flag to "-1" when it finds Role 3 but then when it continues to work, it also find a different role for the same course, and changes the flag back to "0."
Does anyone have any suggestions for how to handle this?
Sorry for the long explanation. I hope this makes sense. Thank you.