Linking button to checkbox and undoing changes

Kronix

Registered User.
Local time
Today, 01:43
Joined
Nov 2, 2017
Messages
102
I have a toggle button that changes its color and caption whenever an option is chosen. I made a checkbox linked to a field to store the value, hid it, and then made the toggle button that checks or unchecks the hidden box in it's onClick event, along with changing the appearance of the button itself.

The problem is when I click the button to change the checkbox, but press the escape button to cancel the changes before the record is saved, the button does not revert back even though the checkbox does. This makes sense since the change in the button is done purely with VBA code, but I don't know how to detect if the button should be reverted or not. The form's Undo event only fires before the reversion of the checkbox takes place.
 
Are you aware a toggle button can be bound to a yes/no field? You don't need to manipulate a checkbox.

To your question, the first thing that comes to mind is the undo event. If that doesn't work, either disabling the escape key or resetting the toggle in one of the Key events after seeing if the escape key was pressed.
 
It's not a built in toggle button because I don't want it to look like it's pressed down for one of the options. The button should only change color and text. As for the key events, that still doesn't give me a way to know whether the checkbox was one of the items that was reverted or it remained unchanged.
 
Is the button something like the one in this thread? See posts 6/7 for details
https://www.access-programmers.co.uk/forums/showthread.php?t=297578

attachment.php
 
Yes, but again I don't know how to make it switch back when the user presses escape to undo. Access only automatically switch controls back if they are bound through Access to the underlying table field.
 
Whenever you have controls that are dependent on other controls, you need code in at least two events to manage the change.
1. The form's Current event. Every time you move to a new record, you need to check the value of fldA so you can properly set fldB
2. The fldA AfterUpdate event so you can toggle the setting of fldB
 

Users who are viewing this thread

Back
Top Bottom