This is a very basic thing however I have not used VBA in 5 years. I have an access form that i would like to use a command button on to set the sheet property from editable and uneditable by clicking the button. I feel like this should only be a few lines of code. any help would be much appreciated.
to give more information I would like a button that changes the property sheet for a form. the specific property is allow edits. I would like to have a button that changes it to yes and a button that changes it to no.
Thank you!
First, you cannot have command button be visible on a form where the "Allow Datasheet View" property is set to "Yes" and all other view are set to "No" and your "Default View" property set to "Datesheet".
If you want to have the datasheet look, try setting your "Default View" property value to "Datasheet" and setting the "Allow Form View" property value to "Yes" and the "Allow Datasheet View", "Allow Pivot Table", and "Allow Pivot Chart View" property values to "No". With these settings, Command buttons and other controls will be accessable.
Here is code for the "On Click" event of a command button named "cmdSetEditStatus" that will toggle the editing capability of the form from editable to non-editable each time you click the button.
Code:
Private Sub cmdSetEditStatus_Click()
If Me.AllowEdits = True Then
Me.AllowEdits = False
Me.cmdSetEditStatus.Caption = "Editing Locked"
Else
Me.AllowEdits = True
Me.cmdSetEditStatus.Caption = "Editable"
End If
End Sub
Just change the name of the button in the appropriate places. I am also changing the "Caption" property of the button to show "Editable" when editing is possible and "Editing Locked" when records cannot be edited.