Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

How can I save the record when a checkbox is either checked or unchecked?

I have a form with several checkboxes.  How can I save the record when a checkbox is either checked or unchecked?
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

You mean check if the check boxes are in a specific state, or when one of them is checked, save the record?

Jim.   
Avatar of SteveL13

ASKER

When they are either checked if they were unchecked OR unchecked if they were checked.
The reason for this is the user can have two forms open at a time and the change has to be reflected in the form other than the one the change was made in.  Make sense?
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do I need to put they code in every AfterUpdate event of every checkbox?  There are 40 of them.
You can change it to one little subfunction which you then call with one line of code from each checkbox.

However, the clever method is to use WithEvents. It takes a little to get into, but once settled, it is plain easy to implement.
You can study my article:

Create Windows Phone Colour Palette and Selector using WithEvents

for a very similar example (using the click event of a label).
This will demand zero code to be typed for each checkbox.
If you're using a bound form, Access is going to save the record whether you've checked the box or not, assuming you've dirtied the record. Gustav's suggestion would immediately save the record.
In order for the change to be reflected, the "other" form would have to requery/refresh the datasource for the form. You could do that from the first form, but that could cause issues with the "other" form - for example, if the user there has made changes, those changes may not be saved.