I have form that displays information on a project. Most of the fields on the form are bound to a Project table and display and update as bound fields do. However, I also have 10 checkboxes that come from a ProjectAudience table. Only if the box on the form is checked, is there is a matching record in the table. Therefor, I need to insert and delete records as these boxes are checked and unchecked.
I can do it at the checkbox level with the AfterUpdate event, but that would require 10 different events. I looking to do it at the Form level by deleting all records in the ProjectAudience tabl开发者_运维技巧e for that project and adding in the checked ones.
Basically, I'm looking for the opposite of the Form_Current event that will fire when either the record navigation button is fired or the form is closed. I'm trying to avoid either writing my own navigation buttons or adding a "SAVE" button to the form that the user must press. I want something automatic that will update this table when the user navigates away from the record.
Based on a comment below: Any combination of boxes from none to all can be checked not just a single box. Therefore, it is possible that I would wipe out all records and not insert any back... or add 10 records if every box was checked. (Also, I am using Microsoft Access 2003)
Have you considered adding these checkboxes to an Option Group and using events from that group?
EDIT re Comment, Alternative approach, do not use an option group, but add code to an event line for all relevant options.
You do not need code for 10 different events, you can set the event line for, say, On Click to the name of a function, let us say:
On Click : =TestMe()
Event Line http://ltd.remou.com/access/EventLine.png
You then need a function:
Function TestMe()
MsgBox "You clicked " & Screen.ActiveControl.Name
End Function
You can use the BeforeUpdate method. However, if only the checkboxes have been changed this event will not fire since the record to which the form is bound didn't change.
I would advise to link events to the checkboxes. Create a function UpdateCheckbox(CheckboxID as integer) that does what you want and put this in the 'OnClick' event from the ckeckboxes: =UpdateCheckbox(1). Change the 1 for the different checkboxes.
精彩评论