Go Premium for a chance to win a PS4. Enter to Win


Color all controls to windows defaults

Posted on 2004-09-15
Medium Priority
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 800 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 ???

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 1200 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

916 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