Example Apps for Businesses, Schools & Developers

Version 1.2           Approx 0.6 MB (zipped)                 First Published 31 Jan 2024


Most experienced Access developers will try to make their applications look consistent in terms of colours and fonts.
For example, all forms in my example apps normally look similar to this:

Example Form
A consistent appearance / style can be achieved using Access themes or saved template forms
Using themes, the appearance of all forms can be quickly changed to suit individual clients. However, many Access users do not find themes easy to work with.

This article and example app demonstrates a different approach which is very easy to apply.



Example App

The main form provides 10 different colours for the background of all forms in the app.

MainForm
Click any colour in the option group and the background colour of the detail section of each form will be instantly updated.

AllForms1

NOTE:
1.   The back color of each form is updated whether or not the form was open at the time

AllForms2
      Take care! Some fairly hideous colour schemes can easily be implemented!

2.   To ensure the label caption text is always legible, the forecolor of all labels in each form is changed from black to white when the form backcolor is red/blue or black.

AllForms3
3.   You can also update the form header and footer sections by enabling 2 lines of code (see below)

AllForms4
      CODE:

Private Sub fraBackColor_AfterUpdate()

      Dim lngBC As Long
      Dim frm As Access.Form
      Dim ctl As Control
      Dim I As Integer
      Dim bIsLoaded As Boolean

      Select Case Me.fraBackColor

      Case 1
            lngBC = vbRed

      Case 2
            lngBC = vbBlue

      Case 3
            lngBC = vbGreen

      Case 4
            lngBC = vbYellow

      Case 5
            lngBC = vbCyan

      Case 6
            lngBC = vbMagenta

      Case 7
           lngBC = vbWhite

      Case 8
            lngBC = vbBlack

      Case 9
            lngBC = RGB(128, 128, 128)    'grey

      Case 10
            lngBC = RGB(255, 128, 0)     'orange

      End Select

      'loop through & update each form detail backcolor
      Application.Echo False

      For I = 0 To CurrentProject.AllForms.Count - 1

            bIsLoaded = CurrentProject.AllForms(I).IsLoaded

            If Not bIsLoaded Then
                  On Error Resume Next
                  DoCmd.OpenForm CurrentProject.AllForms(I).Name, acDesign
            End If

            Set frm = Forms(CurrentProject.AllForms(I).Name)

            'change section back color to specified color
            'disable any section you want to exclude
            frm.Detail.BackColor = lngBC
            'frm.FormHeader.BackColor = lngBC
            'frm.FormFooter.BackColor = lngBC

            For Each ctl In frm.Controls
                 If ctl.ControlType = acLabel Then
                       Select Case Me.fraBackColor
                        Case 1, 2, 8 'Red, Blue, Black
                              'change forecolor to white for greater contrast
                              ctl.ForeColor = vbWhite
                       Case Else
                              ctl.ForeColor = vbBlack
                        End Select
                  End If
           Next

            If Not bIsLoaded Then
                 On Error Resume Next
                 DoCmd.Close acForm, frm.Name, acSaveYes
           End If

      Next

      Application.Echo True

End Sub


4.   Use the combo box to change the default colour so your preferences are stored for future use

5.   The first 8 colours are the built in VBA colours: vbRed, vbBlue etc.
      Two more colours are also provided (Grey / Orange) based on RGB values
      Alternatively, colours can be based on OLE values. See my free Colour Converter example app.

Colour Converter


Download

Click to download:   SetFormBackColors_v1.2     ACCDB file     Approx 0.5 MB (zipped)



Feedback

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 31 Jan 2024



Return to Example Databases Page




Return to Top