Full Version: Setting New Form Properties When Designing New Forms
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Aquadevel

Hi My 'Utter Friend's,

I'm sure some one has done this.

When creating new forms for an app, its a pain to select like:
Close=no
Min/Max=no
Etc,

When creating new forms, I need a 'quick' way to select a form and change all the settings I need.

Someone must have an idea.... iconfused.gif
rbianco
While I don't have any sample to shoot you at the moment, the approach I used to do this is to create template form.
I created a form that has the common settings (fonts, colors, other propertysettings) that I consistently have to change, and I named it frmTemplate. Then I set that as the default form that Access uses when creating new form. Tools>Options>Forms/Reports tab

But since you want to select an existing form, this will require creating a form that displays the settings commonly changed , and pass in the name of a form, and hitr a GO button. Give a few hours and I could try to post one, unless some other Brainiac here already has one!
Aquadevel

Hi RB,

The template would work dor new forms, But I have an existing db that I need to make a lot of changes to.

Thanks for any help!.. notworthy.gif
Doug Steele
Write a module to open each form in design view, change the desired properties and save the changes.
pere_de_chipstick
Hi Aqua

I go with Doug's suggestion, and have used this in the past to do the same:

CODE
Public Function UpdateAllFormsProp()
On Error GoTo err_proc

    Dim srcFrm As Object
    Dim strFrm As String
    
    For Each srcFrm In Application.CurrentProject.AllForms
        strFrm = srcFrm.Name
        DoCmd.OpenForm strFrm, acDesign
        Set srcFrm = Forms(strFrm)
        With srcFrm
            .SomeProperty1 = SomeValue1    
            .SomeProperty2 = SomeValue2
        End With
        DoCmd.Close acForm, strFrm, acSaveYes
    Next srcFrm

exit_proc:
    Exit Function
    
err_proc:
    MsgBox "Error in Function: 'UpdateAllFormProps'" & Chr(13) & Err.Description
    Resume exit_proc

End Function


Obviously changing
.SomeProperty1 = SomeValue1
.SomeProperty2 = SomeValue2
as appropriate

hth
Aquadevel

Hi Pere & Doug,

I agree I need to loop thru the forms. I ran Pere's code and have an 'Application Error".. confused.gif

I run the following code:

CODE
[/code]
Public Sub UpdateForms()
On Error Resume Next

Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject

For Each obj In dbs.AllForms
DoCmd.OpenForm obj.Name, acDesign

'need property info here....:(

DoCmd.Close acForm, obj.Name, acSaveYes
Next obj
End Sub

[code]


It loops thru all forms, but no property change..

Loops drive me crazy.

Doug Steele
Look closer at Bernie's example. It's not enough to simply open the form: you have to instantiate it (his Set srcFrm = Forms(strFrm) statement), and then work with that instantiation.

And what have you put as the properties you want to change?

In general, using On Error Resume Next is a bad idea: it hides errors that you may need to correct.
Aquadevel

Doug,

Welp,

I've tried Pere's code again, still errors out with 'application error' pullhair.gif
Doug Steele
So what's the exact code you're using? And which line of the code raises the error?
Aquadevel
Doug,

CODE
[/code]

Public Function UpdateAllFormsProp()
On Error GoTo err_proc

    Dim srcFrm As Object
    Dim strFrm As String
    
    For Each srcFrm In Application.CurrentProject.AllForms
        strFrm = srcFrm.Name
        DoCmd.OpenForm strFrm, acDesign
        Set srcFrm = Forms(strFrm)
        With srcFrm
            .Close Button = "No"                  <<<<<<<<<~~~~~~  error's out here   with and without brackets
      
        End With
        DoCmd.Close acForm, strFrm, acSaveYes
    Next srcFrm

exit_proc:
    Exit Function
    
err_proc:
    MsgBox "Error in Function: 'UpdateAllFormProps'" & Chr(13) & Err.Description
    Resume exit_proc

End Function
[code]
Doug Steele
Your syntax is incorrect.

CODE
        With srcFrm
            .CloseButton = False
        End With


For any property you're trying to change, put your cursor into the Property field, and press F1 to get into the Help file. That'll show you the proper way to refer to the property, and what are valid values for the property.
Aquadevel

Doug,


I've been up to long!!!!
you can 'slap me!!.. cheers.gif

Thanks!! uarulez2.gif
pere_de_chipstick
Aqua - glad you got it sorted, and Doug, thanks for following through on my post thumbup.gif (I'd taken an early night here!)

Looking through the code it may have been more robust to reference the instantiated form with it's own form variable,
i.e.
CODE

Public Function UpdateAllFormsProp()
On Error GoTo err_proc

Dim srcFrm As Object
Dim strFrm As String
Dim frmOpen As Form

For Each srcFrm In Application.CurrentProject.AllForms
strFrm = srcFrm.Name
Debug.Print strFrm
DoCmd.OpenForm strFrm, acDesign
Set frmOpen = Forms(strFrm)
With frmOpen
.AllowFormView = True
.AllowDatasheetView = False
.AllowPivotTableView = False
.AllowPivotChartView = False
.AllowLayoutView = False
End With
DoCmd.Close acForm, strFrm, acSaveYes
Next srcFrm

exit_proc:
Set frmOpen = Nothing
Set srcForm = Nothing
Exit Function

err_proc:
MsgBox "Error in Function: 'UpdateAllFormsProp'" & Chr(13) & Err.Description
Resume exit_proc

End Function
'
'


but as this is a bit of code that I only use occasionally and it works, I've never 'fixed' it!

Cheers
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.