Edit checkbox state even if form.AllowEdit=false

amorosik

Member
Local time
Today, 18:56
Joined
Apr 18, 2020
Messages
518
I have a continuous form, linked to the data in the db
In the form header section there are some textboxes, always connected to some fields of the db table indicated on RecordSource
The form initially starts with the property AllowEdit = false, to prevent involuntary modifications by the operator
I would like to use a checkbox, located in the Form Header section, to allow the operator to enable data editing and then to change AllowEdit from false to true
But since the form is already AllowEdit=false, it also prevents me from editing the checkbox, even if this is not linked to any field in the db

Question is: is there any way to allow the operator to modify the checkbox even if the form property AllowEdit=false ?
 
Probably not with a checkbox, but maybe you could use a button?
 
Yes, but I'd like to understand why using a checkbox, detached from the data, isn't possible
 
In simple terms, I think it's because it is still seen as a "data holder" not a command button?
You can't ever edit a button, but you can a checkbox.
 
Try this with a CheckBox:
Code:
Private Sub YourCheckbox_GotFocus()
   if not Me.AllowEdits then Me.AllowEdits = True
End Sub

Private Sub YourCheckbox_LostFocus()
   Me.AllowEdits = Me.YourCheckbox.Value
End Sub
 
I'll be darn, I learned something new. I have always avoided using checkboxes for things like that in the past favoring buttons or simply using two forms (one for edit and one for viewing). That code Josef P posted works great.
 
And a side note by way of explanation... Consider that when you click the checkbox, more than one event occurs when AllowEdit = True. You have a _Click event, a _BeforeUpdate event, an _AfterUpdate event, _Enter, _Exit, _GotFocus, _LostFocus... quite a few events.

As a test, see if the click event fires even when AllowEdit = False. If it does, you can toggle the checkbox from the _Click event, because the Allowxxxx flags don't apply to changes made by VBA. They only apply to changes made through the graphic interface.
 

Users who are viewing this thread

Back
Top Bottom