Edit checkbox state even if form.AllowEdit=false (1 Viewer)

amorosik

Member
Local time
Today, 11:08
Joined
Apr 18, 2020
Messages
390
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 ?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:08
Joined
Oct 29, 2018
Messages
21,473
Probably not with a checkbox, but maybe you could use a button?
 

amorosik

Member
Local time
Today, 11:08
Joined
Apr 18, 2020
Messages
390
Yes, but I'd like to understand why using a checkbox, detached from the data, isn't possible
 

Minty

AWF VIP
Local time
Today, 10:08
Joined
Jul 26, 2013
Messages
10,371
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.
 

Josef P.

Well-known member
Local time
Today, 11:08
Joined
Feb 2, 2023
Messages
826
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
 

Mike Krailo

Well-known member
Local time
Today, 05:08
Joined
Mar 28, 2020
Messages
1,044
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:08
Joined
Feb 28, 2001
Messages
27,186
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

Top Bottom