We help IT Professionals succeed at work.

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

SteveL13
SteveL13 asked
on
High Priority
27 Views
Last Modified: 2020-03-24
I have a form with several checkboxes.  How can I save the record when a checkbox is either checked or unchecked?
Comment
Watch Question

Jim Dettman (EE MVE)President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017

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

Jim.   

Author

Commented:
When they are either checked if they were unchecked OR unchecked if they were checked.

Author

Commented:
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?
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
Use the AfterUpdate of the checkbox(es):

If Me.Dirty = True Then
    Me.Dirty = False
End If

Author

Commented:
Do I need to put they code in every AfterUpdate event of every checkbox?  There are 40 of them.
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
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.
Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.