Change Same Parameter on All Forms At Once?

Daveyk01

Registered User.
Local time
Today, 13:39
Joined
Jul 3, 2007
Messages
144
Lets say I wanted to change the "Allow Design Changes" parameter on all forms in a database to either "Design View Only" or to "All Views" via code, can this be done.

The following does not work (be nice if it did):

Public Function frmNoEdit()

Dim MyDB As Database
Dim MyForm As form

Set MyDB = CurrentDb()

For Each MyForm In MyDB
MyForm.AllowDesignChanges = False
Next MyForm
MyDB.Close
Set MyDB = Nothing


End Function

I get the error "Operation is not supported for this type of object" on the "For Each MyForm in MyDB" line.

Thoughts?

Thanks
 
Here's code that does that job. Uses the system table MSysObjects to return a recordset of form names, traverses those opening each form in design view, changing the property and saving the form.
Code:
Sub SetFormPropertyAllowDesignChangesFalse()
'  Sets the 'AllowDesignChanges' property of all forms in the database to 'Design View Only'
   Dim rst As DAO.Recordset
   Set rst = CurrentDb.OpenRecordset( _
      "SELECT [Name] FROM MSysObjects WHERE [Type] = -32768")
   With rst
      Do While Not .EOF
         DoCmd.OpenForm !Name, acDesign, , , , acHidden
         Forms(!Name).AllowDesignChanges = False
         DoCmd.Close acForm, !Name, acSaveYes
         .MoveNext
      Loop
      .Close
   End With
End Sub
 
Excellent. Now I will add that as a maintenance menu function to enable and disbable that. Actually there is very little use to enable this function outside of design mode, but I've had uses for it recently and this is a whole lot easier than editing every form manually - no mistakes and missed forms.

Thank you!
 
I know this isn't exactly related to the original post, but is there a way to use the object MySysObjects to return a list of table names based on a criteria? Like all the table names starting with numbers? An SQL statement wouldn't work because the WHERE clause would apply to the table names, and you wouldn't be able to fill in the SELECT statement.
 
What about ...
Code:
  "SELECT [Name] " & _
  "FROM MSysObjects " & _
  "WHERE IsNumeric(Left([Name], 2)) " & _
    "OR IsNumeric(Left([Name], 3))"
 
Where would I put that code so that the names would show up in a combo box?
 
Remove the quotes and put it in the RowSource property of the combo.
 
wow, that's awesome! This will make things much easier for my user, Thanks!
 

Users who are viewing this thread

Back
Top Bottom