Skip to content

Instantly share code, notes, and snippets.

@NPS-ARCN-CAKN
Last active December 21, 2015 16:28
Show Gist options
  • Save NPS-ARCN-CAKN/ad029417c58fb85aa80d to your computer and use it in GitHub Desktop.
Save NPS-ARCN-CAKN/ad029417c58fb85aa80d to your computer and use it in GitHub Desktop.
Access: Toggle a form's editability (Read only/Editable)
' this button allows the user to switch between read only and editing
Private Sub ToggleReadOnlyButton_Click()
SetFormEditability
End Sub
' you can only toggle the form's allowedits property is it is clean so if the
' form is dirty then ask if it's ok to flush changes
Private Sub SetFormEditability()
If Me.Dirty = True Then
If MsgBox("Save changes?", vbYesNo, "Confirm") = vbYes Then
ToggleFormReadOnly
End If
Else
ToggleFormReadOnly
End If
End Sub
' toggles the form's editability
Private Sub ToggleFormReadOnly()
If Me.AllowEdits = True Then
If Me.Dirty Then Me.Dirty = False
Me.AllowEdits = False
Me.AllowAdditions = Me.AllowEdits
Me.AllowDeletions = Me.AllowEdits
Me.ToggleReadOnlyButton.Caption = "(Read only)"
Else
If Me.Dirty Then Me.Dirty = False
Me.AllowEdits = True
Me.AllowAdditions = Me.AllowEdits
Me.AllowDeletions = Me.AllowEdits
Me.ToggleReadOnlyButton.Caption = "(Editable)"
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment