Color all controls to windows defaults

Posted on 2004-09-15
Last Modified: 2008-01-09

Is there a way to set the colors of all of the controls in all of forms that you may have in an access database to use windows default colors.
I mean is there a way to create a function (if it doesn't already exist on the net) that loops through all of the forms, and then for each form loops through every control and sets the color properties,
taking into account not only the back and fore colors, but also the color of the selected text, and so on.

Or what would be the quickest way to accomplish something like this, considering you have many form in the database with various controls.

Thanks for all the help
Question by:skyrise11
  • 6
  • 3
  • 2
LVL 41

Assisted Solution

shanesuebsahakarn earned 200 total points
ID: 12071390
To cycle through all forms and all controls, and set the appropriate colours, you can do something like this:

Dim rst As DAO.Recordset
Dim ctl As Control

Set rst=CurrentDb.OpenRecordset("SELECT [Name] FROM MSysObjects WHERE Left$([Name],1)<>'~' AND MSysObjects.Type=-32768")
While Not rst.EOF
   DoCmd.OpenForm rst![Name],acDesign
   For Each ctl In Forms(rst![Name])
      Select Case ctl.Type
      Case acTextBox:
         'Set your properties here
      Case acComboBox:
   DoCmd.Close acForm, rst![Name], acSaveYes
Set rst=Nothing
LVL 39

Expert Comment

ID: 12073878
I usually set up 1 default form with all controls and set the various format properties manually and then use AutoFormat to store this as "Windows Standard". I then change the default form (in options) to Windows default. The following table wil tell you the color number in Access, HEX, vb constant and finally what kind of windows "thing" the color represents. I hope this looks OK ...

ColorID                       ColorHex                      VBColorConst             ColorDesc
-2147483648      &H80000000&      vbScrollBars      System Scroll bar
-2147483647      &H80000001&      vbDesktop                      System Desktop
-2147483646      &H80000002&      vbActiveTitleBar      System Active window titlebar
-2147483645      &H80000003&      vbInactiveTitleBar      System Inactive window titlebar
-2147483644      &H80000004&      vbMenuBar                      System Menu background
-2147483643      &H80000005&      vbWindowBackground      System Window background
-2147483642      &H80000006&      vbWindowFrame      System Window frame
-2147483641      &H80000007&      vbMenuText      System Menu text
-2147483640      &H80000008&      vbWindowText      System Window text
-2147483639      &H80000009&      vbTitleBarText      System Caption, size box, scroll arrow text
-2147483638      &H8000000A&      vbActiveBorder      System Active window border
-2147483637      &H8000000B&      vbInactiveBorder      System Inactive window border
-2147483636      &H8000000C&      vbApplicationWorkspace  System MDI application background
-2147483635      &H8000000D&      vbHighlight                      System Items selected in a control, background
-2147483634      &H8000000E&      vbHighlightText      System Items selected in a control, text
-2147483633      &H8000000F&      vbButtonFace      System Command button face
-2147483632      &H80000010&      vbButtonShadow      System Command button edge
-2147483631      &H80000011&      vbGrayText      System Grayed (disabled) text
-2147483630      &H80000012&      vbButtonText      System Command button text
-2147483629      &H80000013&      vbInactiveCaptionText      System Inactive caption text
-2147483628      &H80000014&      vb3DHighlight      System 3-D display elements, highlight
-2147483627      &H80000015&      vb3DDKShadow      System 3-D display elements, darkest shadow
-2147483626      &H80000016&      vb3DLight                      System 3-D display elements, between highlight and shadow
-2147483625      &H80000017&      vbInfoText                      System ToolTips text
-2147483624      &H80000018&      vbInfoBackground      System ToolTips background

LVL 39

Expert Comment

ID: 12073888
ack ... you were asking how to change existing ... after setting up "Windows Standard" you could , ugh, manually open each from in design mode and use AutoFormat to reset to Windows Standard.

who has the code to execute this ???  shane ???

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

LVL 41

Expert Comment

ID: 12073903
Probably the easiest way would be to use code similar to my loop above to loop through all the forms and use RunCommand and (yiccckkkk) SendKeys to achieve something like that - I'm not sure, I've never done AutoFormat via code :-)
LVL 39

Expert Comment

ID: 12074077
I have something similar to your code but I iterate the AllForms collection rather than using system tables. This code was written to standardize border width and menubar properties but could be expanded . I can see how it could get really long ... Select Case for each control type and a nested Select Case for exceptions inside each of the control type Cases. I think code (yours, mine, whatever) would be a better route as AutoFormat replaces EVERYTHING, no exceptions.


Public Function CleanGUI()

'this resets all lines, borders and menubar properties
'on all forms and reports
Dim aob As AccessObject
Dim frm As Access.Form
Dim rpt As Access.Report
Dim ctl As Access.Control

On Error GoTo ERR_CleanGUI
    For Each aob In CurrentProject.AllForms
        DoCmd.OpenForm aob.Name, acDesign
        Set frm = Forms(aob.Name)
        For Each ctl In frm
            If ctl.ControlType <> acCommandButton Then
                ctl.BorderWidth = 1
            End If
        frm.MenuBar = "BJs Data Menu"
        DoCmd.Close acForm, frm.Name, acSaveYes

    For Each aob In CurrentProject.AllReports
        DoCmd.OpenReport aob.Name, acDesign
        Set rpt = Reports(aob.Name)
        For Each ctl In rpt
            ctl.BorderWidth = 1
        rpt.MenuBar = "BJs Report Menu"
        DoCmd.Close acReport, rpt.Name, acSaveYes

    Exit Function
        MsgBox Err.Number & " " & Err.Description
        Resume EXIT_CleanGUI
End Function
LVL 41

Expert Comment

ID: 12074088
I'm just used to using MSysObjects - I only switched to A2K2 about a year ago :)
LVL 39

Expert Comment

ID: 12074231
I remember when MS said to never use Msys because they could "change" as they really were Access internals but I do remember reading an article fairly recently where soemone from MS said that compatibility is number one and that it was "unlikely" that MSys changes would break older apps now and for the foreseable future which makes it sound OK to use but years of habit are hard to break. I wish I had a reference to that article ... found it ...

interesting ... while looking for the article I ran across a reference from Michael Kaplan about /decompile which talks about conanical and P-code. I think you participated recently in a post regarding performance differences between VB and VBA and someone suggested that it might be that VBA uses pcode rather than fully compiled ... coming from Mr. Kaplan and his close association with Access and now working for MS I would say the pcode comment was right on.


Author Comment

ID: 12077869
Cool, makes life a lot easier.

But how do I set the color values for such things as selected text to use window's COLOR_HIGHLIGHT, and COLOR_HIGHLIGHTTEXT values. For example to a Combo Box.
The controls don't seem to provide these color properties.

LVL 39

Expert Comment

ID: 12082890
Unless you subclass the controls with win32 api or build and deploy you own activex controls you are left with lettings Windows pick an appropriate selected text color based on the foreground/ background colors.


Author Comment

ID: 12086653
But is this possible in VBA, I know it can be done in VB. Can you please provide an example or a link?

LVL 39

Accepted Solution

stevbe earned 300 total points
ID: 12091253
Access does not provide reliable window handles to it's internal controls so if you want complete control you would have to build ActiveX controls (using VB) and then register those components and use them instead i=of the ones Access provides. Have you found that the selected text is incorrect if you set the forecolor to ...

-2147483640     System Window text


Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now