Iterating Through all Forms and changing Form Properties.

ions

Access User
Local time
Today, 01:56
Joined
May 23, 2004
Messages
816
Hello

I'm trying to set the GridX and GridY properties of all my forms to 24.

***** Here is a potential Solution I've come up with but don't like it because I would have to open all the forms****
Code:
Start to Iterate through CurrentProject.AllForms collection

	Get the 'name property' of the AccessObject 

	Open the Form using the 'name property' and the Docmd.openform

	Use Forms collection to finally modify the GridX and GridY.

End Iteration

Other related question

a) Why doesn't the Database object (CurrentDB) contain FormsDef, ReportsDef etc...?

b) Is there a complete Diagram of the Access Object Model. I don't see the relationship between Application Object and the DBEngine Object (DAO).
I believe Application supersedes DBEngine because currentDB is a method of the Application object right?
 
I believe you can use:
Code:
Dim frm as Form
Dim strFormName as String

For each frm in Forms
    strFormName=frm.Name
    Docmd.OpenForm strFormName
        <<<not sure about the grid stuff here>>>
    DoCmd.Close acForm, strFormName, acSaveYes    
Next frm
 
Sorry, I guess I answered the question in the way you DIDN'T want to be answered. Sorry about that.
 
That will work , won't it Bob.

Do you need to openform in acdesign mode or something similar?

I use similar stuff to set background images, help files etc in all my forms.

If you do this with a command buytton on a from, you want to ignore that from itself, and maybe any other open forms.
 
Hi Bob your method doesn't work because the Forms collection only contains open forms......

However, it does sound that to do what I want I must OPEN each form (in design view). I will wait a little longer for some more input otherwise I will implement the very ineffecient method I described.
 
Code:
        Dim tmpOBJ as AccessObject
        
        For Each tmpObj In Application.CurrentProject.AllForms
           'do yer stuff here
        Next tmpObj

personally, I would use the form.Move command
Code:
Form.Move(Left, Top, Width, Height)
 
This should work for you. I tested it:
Code:
    Dim obj As AccessObject, dbs As Object
    Dim intCount As Integer
    Set dbs = Application.CurrentProject
    For Each obj In dbs.AllForms
        
        If obj.Type = 2 Then
            DoCmd.OpenForm obj.Name, acDesign
                Forms(obj.Name).GridX = 24
                Forms(obj.Name).GridY = 24
            DoCmd.Close acForm, obj.Name, acSaveYes
        End If
    Next obj
 
Hi Bob I guess I will do it by opening all the forms but I am surprised this is the only way. Thanks for your help. I cleaned up your code a bit and thanks for writing the above code.
Code:
    Dim obj As AccessObject
    For Each obj In CurrentProject.AllForms
        DoCmd.OpenForm obj.Name, acDesign
        Forms(obj.Name).GridX = 24
        Forms(obj.Name).GridY = 24
        DoCmd.Close acForm, obj.Name, acSaveYes
    Next obj
 
Last edited:
Wow! I'm going through a DB Object Enumeration project and this answered my problem of getting "Record Source" values for forms/reports! THANKS!

Now, I just need to figure out how to save the SQL statement of a saved Query...

Yes, I am new to Access, but am an old diehard 80's Programmer who came out of the caves... :-)
 
The gridx and gridy properties are design time properties not run time properties. Hence they have to be set by opening the form in design mode. Now the only problem is to stop the wicked flickering while the process iterates the forms.

Same with background images etc. Its easier and faster to set everything by code, than checking each form manually.
 
Gemma-the-Husky I am not sure what you mean by design time vs run time because as far as we know (based on the input from this thread) every single Form property can only be updated by Opening the Form. Hence every Form property is design time?
 
No, I think there is a difference.

Some properties, such as recordsource and form size, appearance etc can be set or modified at run-time. Others can only be set at design time.

For instance, I wanted to be able to alllow user to change form backgrounds, but the only way I could do this was to set the form background as a linked file rather than embedded

eg c:\my_backs\norm.bmp

then modify the norm.bmp file to achieve the result. (which is not the same as doing it in Access). I will go back and see if I can actually set the linked value at run-time, as this would be easier, but I suspect I can't
 

Users who are viewing this thread

Back
Top Bottom