Is there a way to set the same property on all fifty forms in a database via code at the same time instead of manually one at a time?
Is there a way to set the same property on all fifty forms in a database via code at the same time instead of manually one at a time?
Yes. What property?
Are you actually using Access 2007? That might be a problem for my vba solution.
In that case someone else might jump in. The solution algorithm is pretty simple.
1. Get list of form names in a query.
2. iterate through the list as a recordset
3. Open each form in turn in design mode.
4. Change the property
5. Close and save the form
Cosimo-davegri-v01.zip
Here's a version written with ac2019. It might work for you.
form1,2,3, and 4 are just for test. If it works for them, you can try with your database.
For your database, make a backup copy first.
Copy cctblFormNames and ccfrmFormChoices to your DB.
Open ccfrmFormChoices. It must be the ONLY form open. It will list all your forms and subforms. You can move any form you want untouched to the right listbox.
Last edited by davegri; 01-17-2024 at 12:56 AM. Reason: clarif
I'm converting an Access 2003 database to Access 2007 and then I will convert it to a more recent, supported Access version. The current 2007 step, is the first step in my conversion project.
I just stumbled across this code on another Access related website. This code is old and dates from 2006. Does it look like the right idea to set a value for a Form Property (in this case, the code below sets values for the form's X and Y Axes)?Dim obj As AccessObject, dbs As ObjectDim intCount As Integer
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
If obj.Type = 2 Then
DoCmd.OpenForm obj.Name, acDesignForms(obj.Name).GridX = 24Forms(obj.Name).GridY = 24DoCmd.Close acForm, obj.Name, acSaveYesNext obj
End If
dim frm as form
for each frm in forms
frm.properties("the property name").value = "the value"
next frm
maybe?
(if they are open, if not, you have to open them in design mode, i think, on the phone... can't test)
Please click on the ⭐ below if this post helped you.
↓
dim frm as form
for each frm in forms
frm.properties("the property name").value = "the value"
next frm
maybe?
(if they are open, if not, you have to open them in design mode, i think, on the phone... can't test)
Please click on the ⭐ below if this post helped you.
↓
That code looks ok. Not sure what obj.type 2 is.
Instead of the grid reference
Forms(obj.Name).OrderByOnLoad = False
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba
Fairly certain the order by on load property must be either Y/N (or equivalent). The Order By can be null though?
Never mind - I think I misunderstood the comment. However, Order By might exist by default:
When a new object is created, it inherits the RecordSource, Filter, OrderBy, and OrderByOn properties of the table or query that it was created from.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.
Thanks for the help, davegri.Cosimo-davegri-v01.zip
Here's a version written with ac2019. It might work for you.
form1,2,3, and 4 are just for test. If it works for them, you can try with your database.
For your database, make a backup copy first.
Copy cctblFormNames and ccfrmFormChoices to your DB.
Open ccfrmFormChoices. It must be the ONLY form open. It will list all your forms and subforms. You can move any form you want untouched to the right listbox.
And sorry for the delay responding to you.
I had a business emergency that I needed to work on (my real job isn't in tech).
I haven't tried your suggestion, but I will check it out when I have the time. It looks good, though.
Thanks again.
Something sneaked into the OrderBy property on some of my forms, likely from using the right click mouse button and making the incorrect choice on the mouse menu.
This wasn't a problem in Access 2003 when I last used the database. The problem surfaced after I converted the database to Access 2007, which was the version that MS added the "Order by on Load" property to forms, with the default value being "true"; not realizing this at first, havoc ensued when I opened a form for which a value in the form's "sort by" property existed and interfered with the sort order I originally set in the form's record source query. I thought the conversion process had created some kind of corruption!
Already mentioned
Please use # icon on toolbar when posting code snippets.
Cross Posting: https://www.excelguru.ca/content.php?184
Debugging Access: https://www.youtube.com/results?sear...bug+access+vba