Use autokey to toggle form.allowedit

K

krcmd1

is there an easy way to toggle all the forms in my application between
allowing and not allowing edits, e.g. by an autokey?

thanks
 
B

Brendan Reynolds

Public Sub SetAllowEdits(ByVal NewValue As Boolean)

Dim aob As AccessObject
Dim boolOpened As Boolean

For Each aob In CurrentProject.AllForms
If Not CurrentProject.AllForms(aob.Name).IsLoaded Then
DoCmd.OpenForm aob.Name, acDesign, , , , acHidden
boolOpened = True
End If
Forms(aob.Name).AllowEdits = NewValue
If boolOpened Then
DoCmd.Close acForm, aob.Name, acSaveYes
boolOpened = False
End If
Next aob

End Sub

I can't remember for sure, do you need to call a function, not a sub, from
an autokeys macro? If so, just change the above sub to a function, or create
a wrapper function to call the sub.
 
B

Brendan Reynolds

Oops! You wanted to toggle the value, not to pass it as an argument to the
procedure. The following modification would do that ...

Public Sub SetAllowEdits()

Dim aob As AccessObject
Dim boolOpened As Boolean

For Each aob In CurrentProject.AllForms
If Not CurrentProject.AllForms(aob.Name).IsLoaded Then
DoCmd.OpenForm aob.Name, acDesign, , , , acHidden
boolOpened = True
End If
Forms(aob.Name).AllowEdits = Not Forms(aob.Name).AllowEdits
If boolOpened Then
DoCmd.Close acForm, aob.Name, acSaveYes
boolOpened = False
End If
Next aob

End Sub
 
Top