First Published 27 Feb 2023                 Last Updated 7 Mar 2023

Section Links:
          Set Default Properties Manually
          Set Default Properties Using Code
          Update Existing Properties Using Code
          Use Form/Report Templates
          Download
          Further Reading
          Feedback



This is an updated and significantly extended version of an article originally prompted by a question by David Nealey (AKA volcanics) at Utter Access forum

Is there a way to prevent Access from using colons with textboxes? And from placing borders around objects?
I waste lots of time removing colons and borders. I don't want my forms to look like a prehistoric Access application.

There is absolutely no need to waste time doing this! You can easily set the default properties of all controls in Access forms and reports either manually or using code



1.   Set Default Properties Manually                                                                                                                                     Return To Top

To do so, first open a new / existing form in design view then open the form property sheet (if not already open)

In the Form Design ribbon, click on any control you want to customise e.g. label . . . but do NOT drag it to the form

The property sheet will now say e.g. Default Label

FormDesignRibbon
Change any setting to the default value required.

For example if you want the label to have a transparent border, set the label Border Style to Transparent from the Format tab or the All tab of the Property Sheet

Label Border Style (Format tab)

BorderStyleLabel
Label Border Style (All tab: A=>Z)

BorderStyleLabelAZ


NOTE: Changing the properties of a control already on a form only changes that individual control . . . NOT the default control properties

To remove the colon after the caption from the label attached to a textbox, set the Default Text Box Add Colon property to No

Add Colon property(Format tab)

AddColon
Add Colon property (All tab: A=>Z)

AddColonAZ


NOTE: The default for attached labels is ALWAYS set from its associated control type:
           - textbox/combobox/listbox/checkbox/command button/toggle button/option group/option button/attachment/subform/subreport/object frame

This is done so the attached label options can be chosen separately for each item

You can set the default options for all control types by this method. Two more examples:

Image Size mode

ImageSizeMode
Listbox Value Edits

ListBoxValueListEdits


NOTE:
a)   The default settings apply to all new controls on the selected form or report. The settings are not automatically added to new forms or reports
b)   The default options for all controls are saved in a built-in Normal template form & report

ObjectDesignerOptions
c)   However, if preferred you can instead specify a different default template form/report in Access Options.
      Doing this can be useful if you want to set different default values for a specific database.

ObjectDesignerOptionsUpdated
d)   Changing the default settings will not alter any existing form/report controls. This will need to be done either manually or by looping through the controls using code.



2.   Set Default Properties Using Code                                                                                                                                   Return To Top

My thanks to Kent Gorrell for suggesting code to do this in his follow-up article: Access Form Control Default Properties

The following code is slightly adapted from that in his article:

You can use code similar to this to set the default properties for all new controls in a specified form:

Public Sub SetDefaultFormControlProperties(frm As Form)

'sets default properties for all new controls in a specified form
'adapt/extend as appropriate

      Dim ctl As Control

      Set ctl = frm.DefaultControl(acTextBox)
      With ctl
            .Properties("FontName") = "Calibri (Detail)"
            .Properties("FontSize") = "14"
            .Properties("ForeColor") = vbWhite
            .Properties("AddColon") = "Yes"
            .Properties("BackColor") = vbBlue
      End With

      Set ctl = frm.DefaultControl(acComboBox)
      With ctl
            .Properties("FontName") = "Tahoma"
            .Properties("FontSize") = "11"
            .Properties("ForeColor") = vbYellow
            .Properties("AddColon") = "Yes"
            .Properties("BackColor") = vbRed
      End With

      Set ctl = Nothing

End Sub


Example usage: Add the line SetDefaultControlProperties Me to the Form_Load event

A better approach is to use the AllForms collection to loop through all forms to set the default properties for all new controls

Public Sub SetFormDefaultControls()

'sets default properties for all new controls in all existing forms

      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)
                  SetDefaultFormControlProperties frm
            DoCmd.Close acForm, strFormName, acSaveYes
      Next obj

End Sub


Exactly the same methods can be used for reports using the AllReports collection.
However, the properties of existing controls in forms and reports are NOT updated



3.   Update Existing Properties Using Code                                                                                                                          Return To Top

Similar code can be used to update all existing controls in individual forms/reports or to loop through all objects using the AllForms or AllReports collections

Public Sub UpdateAllFormControlProperties()

'updates properties for all controls in all existing forms

      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)
                  UpdateFormControlProperties frm
            DoCmd.Close acForm, strFormName, acSaveYes
      Next obj

End Sub

'-------------------------------------------------

Public Sub UpdateFormControlProperties(frm As Form)

'updates properties for all controls in a specified form

      Dim ctl As Control

      For Each ctl In frm.Controls
            If ctl.ControlType = acLabel Then
                  With ctl
                  'remove colon at end of label caption (if it exists)
                  If Right(.Caption, 1) = ":" Then .Caption = Left(.Caption, Len(.Caption) - 1)
                  'set label border as e.g. transparent; 0=transparent; 1 = solid ... etc
                  .Properties("BorderStyle") = 0
                  End With
            End If

            If ctl.ControlType = acTextBox Then
                  With ctl
                        .Properties("FontName") = "Calibri (Detail)"
                        .Properties("FontSize") = "14"
                        .Properties("Forecolor") = vbBlack
                        .Properties("BackColor") = vbYellow
                  End With
            End If

            If ctl.ControlType = acComboBox Then
                  With ctl
                        .Properties("FontName") = "Times New Roman"
                        .Properties("FontSize") = "10"
                        .Properties("Forecolor") = vbBlue
                        .Properties("BackColor") = vbGreen
                  End With
            End If
      Next ctl

      Set ctl = Nothing

End Sub


However, any new forms/reports that are created after this code is run, will still not use the default properties you have set.
To do this, you can create your own template form / report or use a template database



4.   Use Form/Report Templates                                                                                                                                           Return To Top

Create a blank form / report and set its default control properties. Save as e.g. zfrmTemplateForm / zfrmTemplateReport. See screenshot above
Use as the base object for any new forms / reports

. . . OR take this process one stage further. Set all the defaults as above then save as a template database (.ACCDT file)

At the same time, I suggest you set set other preferences e.g. overlapping windows display, disable layout view etc.
You can then use this template database as a starting point for all new databases

For more details, see my article: Application Parts and Templates



5.   Download                                                                                                                                                                           Return To Top

Example database containing the above code:

      Set Control Defaults     Approx 0.4 MB (zipped)



6.   Further Reading                                                                                                                                                                 Return To Top

For more information about setting control defaults, see these Microsoft articles

      Customize design settings for objects in your database

      Form.DefaultControl property

      Report.DefaultControl property



7.   Feedback                                                                                                                                                                             Return To Top

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington           Mendip Data Systems                 Last Updated 7 Mar 2023



Return to Access Articles Page




Return to Top