Expand Your Access Palette

Use AutoHotkey to bring consistency to your Access color schemes and save time when designing forms.

Expand Your Access Palette

An important part of building a cohesive user interface is using consistent colors.  Newer versions of the Access properties window make this a bit easier, since we can now use hex-based color codes.  

Internally, these hexadecimal representations are converted to long integers.  The hexadecimal representation is written in RGB format, where R is a red value from 0 to 255, G is a green value from 0 to 255, and B is a blue value from 0 to 255.

In older versions of Access, using the RGB format was not an option.  You were forced to use the long integer value directly.

Eventually, I got tired of copying and pasting color values from one control or form section to another.  I also got sick of having to make the hex-to-Access color conversions all the time.

Autohotkey to the rescue

So, as I often do when faced with a menial, recurring task, I turned to Autohotkey to make the problem go away.

Access Palette dialog: note the background colors showing through for color matching purposes

The script I posted below is pretty simple.  When run, the script displays a series of colored squares (see above).  The form's background is made transparent so that you can overlay the colors right next to existing colors for matching purposes.  There is a dropdown in the upper left where you can choose from two color formats, Microsoft Access (the long integer representation) and hexadecimal RGB.

To copy a color's representation, you simply double-click on one of the boxes.  The script copies the representation (long integer or hexadecimal string value) to the clipboard.  You can then paste the saved item into VBA or an appropriate property, like BackColor, ForeColor, etc.

You can easily customize the size of the boxes as well as the colors that are shown.  The idea is that you would preconfigure it with your preferred color palette.  You're more than welcome to use mine, but I recommend you develop your own (or match the color scheme of an existing project).  

Source Code

Here's the script:

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Mike Wolfe <mike@nolongerset.com>
;
; Script Function:
;	Displays a palette of pre-defined colors for use in Microsoft Access.
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

;-------------------------------------------------------
;*** ; Customize colors here
BoxSize = 100
Rows = 6
Row1 = ButtonFace, BBBBFF, FFFFFF, 000000, 9EFFCF
Row2 = 000040, 008000, 800000, 0000A0, FFFF99
Row3 = 5E5E7F, 8C8CBF, D9D9FF, 2F2F40, A8A8E5
Row4 = E6AAFF, 9EFFCF, FFFF99, B4C8FF, E0E0E0
Row5 = 719BC3, 96B3D1, BCCEE2, E0E9F1, FFFFFF
Row6 = 73C270, 99D197, BEE3BC, E2F2E1, FFFFFF
;*
;=======================================================

;*** ; Do not modify below this line
Gui, Color, EEAA99
Gui +LastFound -MinimizeBox ; Make the GUI window the last found window for use by the line below.
WinSet, TransColor, EEAA99

Gui, Add, DropDownList, vColorFormat, MS Access||Web

Loop %Rows%
{
	Colors := Row%A_Index%
	Options = Section
	If (A_Index>1)
		Options = Section xs
	Loop, parse, Colors, `,
	{
		IfEqual A_LoopField, ButtonFace
		{
			Gui, Color, , F0F0F0
			Gui, Add, ListView, W%BoxSize% H%BoxSize% gGetFace %Options%
		} Else {
			Gui, Color, , %A_LoopField%
			Gui, Add, ListView, W%BoxSize% H%BoxSize% gGetColor %Options%
		}
		Options = ys
	}
}

Gui, Show
Return

GetColor:
	MouseGetPos, MouseX, MouseY
	PixelGetColor, color, %MouseX%, %MouseY%
	StringMid R, color, 7, 2
	StringMid G, color, 5, 2
	StringMid B, color, 3, 2
    Gui Submit
    
    if (ColorFormat == "MS Access")
    {
        R = 0x%R%
        G = 0x%G%
        B = 0x%B%
        SetFormat IntegerFast, d
        R += 0
        G += 0
        B += 0
        ColorCode := R + ((2**8)*G) + ((2**16)*B)
    }
    else if (ColorFormat == "Web")
    {
        ColorCode = #%R%%G%%B%
    }
        ;MsgBox The color at the current cursor position is %color%. R: %R%  G: %G%  B: %B%  Access: %AccessColor%
	Clipboard = %ColorCode%
	ExitApp
	
GetFace:
	Clipboard = -2147483633
	ExitApp
	
GuiEscape:
GuiClose:
ExitApp

Running the script

To run the above script, you will first need a copy of AutoHotkey.  After downloading and installing Autohotkey, you need to save the above script to a file named AccessTemplate.ahk.  Then, you can just double-click the script file and the script window will launch immediately.

I like to take things a step further and set a hotkey to call the script file from one of my startup AutoHotkey scripts.  That way, the palette is always just a shortcut way.  Here's what that looks like.  Note that I've assigned my Access Palette script the shortcut key [Ctl] + [Shift] + [Z]:

^+z::Run %A_ScriptDir%\AccessPalette.ahk ;Ctrl + Shift + z
Launching the AccessPalette script from inside another AutoHotkey script

Image by armennano from Pixabay

All original code samples by Mike Wolfe are licensed under CC BY 4.0