Access Form Control Default Properties

By | 2023-03-07

To change the default properties for controls in forms and reports using VBA you can use the code below. For example, if you decide to change the default font or font size in your application, rather than manually opening each form and changing the defaults you can loop throught the AllForms collection, open each form in design view, change the defaults and save the form.

Colin Riddington has instructions to do this manually at

https://www.isladogs.co.uk/default-control-properties/index.html

Here is the procedure to iterate your All Forms Collection

Public Sub FormDefaultControl_Update()
Dim obj As Object, frm As Form
Dim strFormName As String

    For Each obj In Application.CurrentProject.AllForms
        strFormName = obj.Name
        DoCmd.OpenForm strFormName, acDesign, , , , acHidden
            Set frm = Forms(strFormName)
            DefaultControlProperties_Update frm
        DoCmd.Close acForm, strFormName, acSaveYes
    Next obj

End Sub

Which Calls the procedure to change the control defaults

Public Sub DefaultControlProperties_Update(frm As Form)
Dim ctl As control

    Set ctl = frm.DefaultControl(acTextBox)
    With ctl
        .Properties("FontName") = "Calibri (Detail)"
        .Properties("FontSize") = "11"
    End With
    
    Set ctl = frm.DefaultControl(acComboBox)
    ctl.Properties("FontName") = "Calibri (Detail)"
    ctl.Properties("FontSize") = "11"
    
End Sub