Set the Ralph control source for the function, for example =GetCheckState() . Then create a function like this:
Public Function GetCheckState() as boolean If Frank then GetCheckState = True Else GetCheckState = False End If End Function
This will control whether Ralph is checked or not based on Frank. Since the checkbox is bound to a function, it will not allow you to change the value by clicking it.
To respond to the user by clicking the field, add the code to the On Mouse Up event:
Private Sub Ralph_MouseUp(Button As Integer, Shift As Integer, _ X As Single, Y As Single) If Button = acLeftButton And Not Frank Then Frank = True End If Ralph.Requery End Sub
The Click event seems completely ignored when the function is the source of control, so you should use On Mouse Up (On Mouse Down works if you prefer this). You can also add similar code to the KeyDown event if you want the window to check when users press the spacebar or enter a key.
The only disadvantages are:
- The box is not grayed out if it cannot be clicked.
- Access will display a message in the status bar saying that the control cannot be edited due to the expression to which it attached when it pressed.
In the first case, you can display a message explaining this if you think that people will be embarrassed. Secondly, there is probably a way around it, but I could not find it. The message still appears even when I tried to set up my own status message in both the Mouse and Mouse events.
If you have a window with a gray color when it is turned off, this is very important for you, then this will not work, but I was dissatisfied with the appearance of the "simulated" flag that was proposed in the accepted answer. This method allowed me to control the functionality of the flag based on other entries and still use the actual flag.
source share