Solved

Color all controls to windows defaults

Posted on 2004-09-15
11
501 Views
Last Modified: 2008-01-09
Hi,

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
0
Comment
Question by:skyrise11
  • 6
  • 3
  • 2
11 Comments
 
LVL 41

Assisted Solution

by:shanesuebsahakarn
shanesuebsahakarn earned 200 total points
Comment Utility
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:
         'etc
      ....etc....
   Next
   DoCmd.Close acForm, rst![Name], acSaveYes
   rst.MoveNext
Wend
rst.Close
Set rst=Nothing
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
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


Steve
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
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 ???

Steve
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
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 :-)
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
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.

Steve

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
   
    'forms
    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
        Next
        frm.MenuBar = "BJs Data Menu"
        DoCmd.Close acForm, frm.Name, acSaveYes
    Next

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

EXIT_CleanGUI:
    Exit Function
   
ERR_CleanGUI:
        MsgBox Err.Number & " " & Err.Description
        Resume EXIT_CleanGUI
End Function
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 41

Expert Comment

by:shanesuebsahakarn
Comment Utility
I'm just used to using MSysObjects - I only switched to A2K2 about a year ago :)
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
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 ...
http://www.trigeminal.com/usenet/usenet017.asp?1033

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.
http://www.trigeminal.com/usenet/usenet004.asp?1033

Steve
0
 

Author Comment

by:skyrise11
Comment Utility
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.

0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
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.

Steve
0
 

Author Comment

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

Thanks.
0
 
LVL 39

Accepted Solution

by:
stevbe earned 300 total points
Comment Utility
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

Steve
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views 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 Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

772 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

11 Experts available now in Live!

Get 1:1 Help Now