VBA for command button to set sheet property in access 2010 (1 Viewer)

stepp24

New member
Local time
Today, 09:14
Joined
Aug 22, 2011
Messages
3
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.
 

stepp24

New member
Local time
Today, 09:14
Joined
Aug 22, 2011
Messages
3
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!
 

Mr. B

"Doctor Access"
Local time
Today, 08:14
Joined
May 20, 2009
Messages
1,932
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.
 

Users who are viewing this thread

Top Bottom