Use autokey to toggle form.allowedit

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top