Changing Colours on Forms (1 Viewer)

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
Hello everyone,

I'm quite advanced with writing my Technical Support database, so far that we are about to roll it out to users in the States (using a mixture of VPN, form timing and other things my IT bod has helped with).

It has been well received but now one of the test users has said "great database - but can I change the colours" e.g form backgrounds, buttons, font colours etc of the forms on the fly. We have corporate colours for the forms which match our other pieces of software we sell (this DB is not for sale BTW).

I have in 35 or so forms that may need to be changed. the only thing I can think of doing is writing a new module that has the default corporate colours, then make a form with the controls on it for them to pick the colours and apply them.

I have no idea how to cycle through the controls or the forms in the database. Anyone done something similar? or should I just tell them to s*d off?

many thanks in advance

Cliff
 

isladogs

MVP / VIP
Local time
Today, 02:18
Joined
Jan 14, 2017
Messages
18,247
Anyone done something similar? or should I just tell them to s*d off?

Very tempting ....:D
Or you can use an Access theme for all your forms and allow users to change the theme

There is a very clever Theme Manager by forum member davegri.
It may be a bit over the top for your needs but it will certainly work!
 

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
Cheers isladogs great little colour changer. I've just got to alter it a little so that when a user changes the setting it is saved for that user only and everyone else who feels the need to change the default setting...that reminds me need a default button on there somewhere

Cliff
 

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
Cheers Uncle

don't think the boss will want me paying for something like that but good call
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:18
Joined
Sep 21, 2011
Messages
14,369

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:18
Joined
May 21, 2018
Messages
8,555
I will post something this evening. I need to do some clean up to make it more generic.

The gist was there is a settings table.
I will post something this evening. I need to do some clean up to make it more generic.

The gist was there is a settings table.

SettingID SettingName SettingValue
1 ForeColor 0
2 BackColor 16711680
3 FontName Bernard MT Condensed
4 FontSize 16
5 FontWeight 400
7 FontUnderline True
8 FontItalic True


I had a form with the ability to set these values. You could add more features.
then I made this module
modPersistSettings
Code:
Option Compare Database
Option Explicit
Public Enum CustomSetting
  csForeColor = 1
  csBackColor = 2
  csFontName = 3
  csFontSize = 4
  csFontWeight = 5
  csFontItalic = 6
  csFontUnderline = 7
  'you could add more
End Enum
'--------------------- Update the Setting Table --------------------------------
Public Sub UpdateSetting(Setting As CustomSetting, SettingValue As String)
  Dim strSql As String
  Dim SettingName As String
  SettingName = GetSettingName(Setting)
  strSql = "Update tblSettings set Settingvalue = '" & SettingValue & "' where SettingName = '" & SettingName & "'"
  Debug.Print strSql
  CurrentDb.Execute strSql
End Sub
'--------------------- Retrieve from setting table ---------------------------------
Public Function GetSetting(Setting As CustomSetting) As String
  Dim SettingName As String
  SettingName = GetSettingName(Setting)
  GetSetting = DLookup("SettingValue", "TblSettings", "SettingName = '" & SettingName & "'")
End Function
Public Sub ApplyCustomSettings1(frm As Access.Form, Optional TheTag As String = "All_Controls")
  'This version uses the Table control types to see if the property exists
  'For demonstration, I do not think the bang is worth the buck
  Dim ctrl As Access.Control
  Dim rs As DAO.Recordset
  For Each ctrl In frm.Controls
     If ctrl.Tag = TheTag Or TheTag = "All_Controls" Then
        If HasProperty("ForeColor", ctrl.ControlType) Then ctrl.ForeColor = GetSetting(csForeColor)
        If HasProperty("BackColor", ctrl.ControlType) Then ctrl.BackColor = GetSetting(csBackColor)
        If HasProperty("FontName", ctrl.ControlType) Then ctrl.FontName = GetSetting(csFontName)
        If HasProperty("FontWeight", ctrl.ControlType) Then ctrl.FontWeight = CLng(GetSetting(csFontWeight))
        If HasProperty("FontSize", ctrl.ControlType) Then ctrl.FontSize = GetSetting(csFontSize)
        If HasProperty("FontUnderline", ctrl.ControlType) Then ctrl.FontUnderline = GetSetting(csFontUnderline)
        If HasProperty("FontItalic", ctrl.ControlType) Then ctrl.FontItalic = GetSetting(csFontItalic)
     End If
  Next ctrl
End Sub
Public Function HasProperty(PropName As String, ControlType As Long) As Boolean
  'Used with applyCustomSettings1
  'This may be more work than it is worth. You would have to keep the table updated. You are probably better off just trapping the error if the property does not exist
  HasProperty = Nz(DLookup(PropName, "tblControlTypes", "ControlTypeValue = " & ControlType), False)
End Function
Public Sub ApplyCustomSettings2(frm As Access.Form, Optional TheTag As String = "All_Controls")
  'This version just traps the error if that control type does not support the property
  On Error GoTo errLbl
  Dim ctrl As Access.Control
  Dim rs As DAO.Recordset
  
  For Each ctrl In frm.Controls
     If ctrl.Tag = TheTag Or TheTag = "All_Controls" Then
        ctrl.ForeColor = GetSetting(csForeColor)
        ctrl.BackColor = GetSetting(csBackColor)
        ctrl.FontName = GetSetting(csFontName)
        ctrl.FontWeight = CLng(GetSetting(csFontWeight))
        ctrl.FontSize = GetSetting(csFontSize)
        ctrl.FontUnderline = GetSetting(csFontUnderline)
        ctrl.FontItalic = GetSetting(csFontItalic)
        'You can add additional properties as desired
     End If
  Next ctrl
  Exit Sub
errLbl:
  If Err.Number = 438 Then ' Property not supported. This is probably faster than trying to determine if property exists
    Resume Next
  Else
    Debug.Print Err.Number & ": " & Err.Description
  End If
End Sub
Public Function GetSettingName(CustomSetting As CustomSetting) As String
   Select Case CustomSetting
    Case 1
      GetSettingName = "ForeColor"
    Case 2
      GetSettingName = "BackColor"
    Case 3
      GetSettingName = "FontName"
    Case 4
      GetSettingName = "FontSize"
    Case 5
      GetSettingName = "FontWeight"
    Case 6
      GetSettingName = "FontItalic"
    Case 7
      GetSettingName = "FontUnderline"
   End Select
   'you can add additiona properties as desired
End Function

Then on the forms on open you can apply custom settings to all controls or tagged controls
modPersistSettings.ApplyCustomSettings2 Me, "A"
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:18
Joined
May 21, 2018
Messages
8,555
So that example would allow users to modify dynamically the controls. If you want to simply change properties of controls and forms one time, looping is relatively easy. You can add additional properties
Code:
Private Sub cmdOk_Click()
  Dim frmObj As Access.AccessObject
  Dim frm As Access.Form
  Dim frmName As String
  For Each frmObj In CurrentProject.AllForms
     frmName = frmObj.Name
     If Not frmName = "FrmChangeColor" Then
        DoCmd.OpenForm frmName, acDesign, , , , acHidden
        Set frm = Forms(frmName)
        ChangeControls frm, Me.TxtForeColor, Me.TxtBackColor
        DoCmd.Close acForm, frmName, acSaveYes
     End If
  Next frmObj
  DoCmd.Close acForm, Me.Name
  DoCmd.OpenForm "Home", , , , , acDialog
  
End Sub

Public Sub ChangeControls(frm As Access.Form, TheForeColor, TheBackColor)
  'Not all controls support the property
  On Error Resume Next
  Dim ctrl As Access.Control
  For Each ctrl In frm.Controls
    ctrl.ForeColor = TheForeColor
    ctrl.BackColor = TheBackColor
  Next ctrl
 
End Sub
 

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
Hi All

Update of the colour changing forms.

My boss was over here for a few days and asked my how it was going, when we are going to roll it out etc. He wasn't best pleased that I was "Wasting your goddam time doing this h****s**t" (he is American BTW) so that has been shelved.

I really have to express my profound thanks to Isladogs, Uncle Gizmo and MajP for all their hard work and advice. When the boss isn't looking and too concerned with the time scales then I will implement the colour picking as I've done the majority of the hard work

once again many thanks to you all.

Cliff
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:18
Joined
May 21, 2018
Messages
8,555
Glad you got is solved and sorry I did not post back. I needed help from Sonic8 to fix the font dialog issue. This is a really good example for converting a 32bit compatible API to 64.
https://www.access-programmers.co.uk/forums/showthread.php?t=303476

Here is a concept for allowing dynamic settings. This is more a novelty than a working solution. There would have to be a lot more features to make it something that would really work. I simplified the table to be less normal, but if I was really to do this I would make the settings table how I had it before.

ThemeID
SettingName
SettingValue
ApplySetting ' THis is a problem now since all settings are applied, but you may not want to apply all the settings like font size. Maybe just the colors.

Anyways, you have a form that lets you add, modify, and select a "theme". I did a few holiday ones. You could add to this form other settings.



From the demo form you can pick a theme and apply it.



Then the applied theme


As I said this is more a novelty IMO. If someone is interested I could update and make it more robust.

I am not very familiar with working with real Access themes so using the real themes as stated might be a much better way to do this.
 

Attachments

  • ThemeV.jpg
    ThemeV.jpg
    47.7 KB · Views: 265
  • Theme1.jpg
    Theme1.jpg
    26.3 KB · Views: 262
  • PickTheme.jpg
    PickTheme.jpg
    43.7 KB · Views: 272
  • Dynamic Settings V3.accdb
    876 KB · Views: 114
Last edited:

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
Hi MajP

that looks brilliant, I will bury it in my DB then uncover it when needed :D
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:18
Joined
May 21, 2018
Messages
8,555
I think it could be fun to check the date and apply those themes on the holiday without telling anyone.
 

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
:D:D:D what a wonderfully wicked idea...
 

isladogs

MVP / VIP
Local time
Today, 02:18
Joined
Jan 14, 2017
Messages
18,247
As I said this is more a novelty IMO. If someone is interested I could update and make it more robust.

I am not very familiar with working with real Access themes so using the real themes as stated might be a much better way to do this.

Just in case you haven't yet done so, it may be worth having a look at davegri's example - see link in post #2
 

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
Hi isladogs
yes I've downloaded the theme manager and it is very good, I've changed one of them for the corporate default so I can revert the db back.

Cliff
 

isladogs

MVP / VIP
Local time
Today, 02:18
Joined
Jan 14, 2017
Messages
18,247
Hi cliff

My comment was mainly meant as a suggestion to MajP
Nevertheless, good to see how this has progressed.

I've always asked clients whether this was really the most important thing they wanted me to work on.
In other words, politely suggesting what you wrote in post #1
 

Cliff67

Registered User.
Local time
Yesterday, 18:18
Joined
Oct 16, 2018
Messages
175
Thankfully the Boss has put a stop to that
 

jall

New member
Local time
Yesterday, 18:18
Joined
Jul 12, 2019
Messages
3
That was really fantastic
Thanks a lot
 

Users who are viewing this thread

Top Bottom