Introduction.
We have already explored the Binary, Octal, and Hexadecimal number systems and learned some simple rules that allow us to devise new number systems with any base value, as long as the user understands the basic rules and can interpret the numbers correctly.
In our previous session, we worked with a form that allowed us to enter decimal numbers, convert them into binary, and also display their corresponding RGB color representation.
If you would like to learn and understand Binary, Octal, and Hexadecimal Number Systems, then check the following Posts:
- Learn the Binary Numbering System
- Learn Binary Numbering System-2
- Octal Numbering System
- Hexadecimal Numbering System
- Colors 24-Bits And Binary Conversion.
This week, we will build a Form-based utility that will be especially useful during the design phase of a new project. With this tool, you can visually create your own 24-bit custom colors and save up to 15 colors in a color palette within the form. Any of these saved colors can then be applied to the form background, or to the foreground, background, or border color properties of other controls at design time.
For reference, an image of the Employees Form in Design View is shown below, displaying the form’s Header Section Property Sheet alongside the Color Palette Form.
The Color Palette Usage
A new custom color is created on the Color Palette Form (see the large rectangle) and then applied to the Employees Form Header Section background by setting its value in the Back Color property.
Click on the image to enlarge it. The Employees Form is shown in Design View, with the Header Section selected. Its Property Sheet is also visible, displaying the Back Color property.
When you click on any of the 15 Color Boxes (which you can create and overwrite with your own saved colors), the corresponding color value is displayed in the text box above the palette, labeled as an RGB Color. You can then copy this value (Ctrl+C) and paste it (Ctrl+V) into the Property Sheet’s Back Color, ForeColor, or Border Color property—depending on where you want to apply it—thus setting the form or control color.
In the Property Sheet, color values appear in hexadecimal format prefixed with a hash symbol (for example: #4E61BC). However, you can directly paste the decimal color value, and Access will automatically convert it into hexadecimal form.
Since we have already learned about the hexadecimal number system, I’d like to draw your attention to a small issue related to this conversion.
A Test Run.
Let us take a sample color number in decimal: 12345678. Enter (or paste) this value into the Form Header or Detail Section Back Color property and press Enter. Access will automatically convert it into a hexadecimal value, such as #4E61BC and the form background will be filled with a dark blue color.
👉 Notice the difference between the first two digits and the last two digits of the hexadecimal number—this is the key to understanding how Access interprets color values.
Checking the value in VBA
-
Open the VBA Editor (Alt+F11).
-
Display the Immediate Window (Ctrl+G).
-
Type the following and press Enter:
The result will be:
This is the raw hexadecimal equivalent of 12345678.
-
If you paste this number into a property in the form of
#BC614EAccess will display a dark red color.
Why do the results differ?
-
When you type the decimal value
12345678directly into a color property, Access reinterprets the bytes internally and reformats them as#4E61BCin 24 Bit RGB order:-
R = 78 (
&H4E) - least significant 8-bit Value. -
G = 97 (
&H61) - middle 8-bit Value -
B = 188 (
&HBC) - most significant 8-bit value.
-
-
On the other hand, when you convert
12345678using VBA’sHex()function, you getBC614E. If this is placed directly into the property (#BC614E)Access does not remap it into RGB order—it takes it literally, which leads to a completely different color.
Conclusion
In both cases, decimal-to-hexadecimal conversion works correctly, just as in the decimal-to-binary method we discussed earlier. However, Access interprets decimal color values and hex color values differently because of the byte order applied internally.
✅ The safest method: Always paste the decimal value into the color property and let Access handle the conversion automatically.
Creating New Colors and Saving Them in the Color Palette.
Now, we will look at the simple trick of designing new Colors (logically, there are over 16 million 24 Bit color values available) and saving them on the Color palette for later use.
You can download a database with the above Form with the Programs from a link at the bottom of this article so that you can import this Form into your new Projects, design your own colors, and use them on your Forms or Controls.
You can click on the above image to enlarge it for a clearer view of the controls on the Form. Let us examine them one by one.
-
Scrollbars (Red, Green, Blue):
There are three scrollbar controls to input integer values ranging from 0 to 255 for the primary colors Red, Green, and Blue.-
Moving a scrollbar to the right increases its value, while moving it to the left decreases it.
-
Clicking on the arrow buttons at either end adjusts the value by 1 with each click.
-
Holding down an arrow button rapidly increases or decreases the value, and the color graph updates accordingly.
-
-
Color Bar Graphs:
On the right of each scrollbar, a vertical bar graph provides a visual representation of the current intensity of each primary color. The corresponding numeric values also appear in the text boxes labeled Red, Green, and Blue. -
Preview Rectangle:
The large rectangle at the bottom-right displays the resulting color created by mixing the Red, Green, and Blue values from the scrollbars. -
RGB Color Text Box:
The text box labeled RGB Color shows the decimal color number representing the combined RGB value.-
You can copy this number (Ctrl+C) and paste it (Ctrl+V) into a Form’s or Control’s Back Color, ForeColor, or Border Color property to apply the new color.
-
-
Saving Custom Colors:
To preserve a newly created color:-
Click on the preview rectangle to select the color.
-
Then click on one of the 15 color boxes on the left to store it there for later use (overwriting any existing color in that box).
-
-
Reusing Saved Colors:
To apply a previously saved color, simply click on the desired color box. The selected color’s decimal number will appear in the RGB Color text box, ready to copy and paste into the appropriate property.
Tips
-
Modify an Existing Color:
If you already have an RGB color number but want to adjust it, copy and paste the decimal value into the RGB Color text box (or type it directly) and press Enter. The selected color will appear in the preview rectangle, while the Red, Green, and Blue text boxes will update with their respective values. The bar chart will also provide a quick visual indication of each color component. From there, you can use the scrollbar sliders to fine-tune the color further. -
Working with Hexadecimal Values (MS Access 2007):
If you are using MS Access 2007, color values are displayed in hexadecimal format. To convert them into decimal numbers for use in the RGB Color text box:-
Open the VBA Debug window (Ctrl+G).
-
Type:
? &hXXxxXX(replace XXxxXX with your six-digit hex value). -
Swap the rightmost two digits with the leftmost two digits of the hex value before conversion.
-
The result will be the decimal equivalent, which you can copy into the RGB Color text box for modification.
-
-
Direct Value Entry:
Instead of using scrollbars, you can type integer values directly (from 0 to 255) into the Red, Green, and Blue text boxes to generate a new color instantly.












No comments:
Post a Comment
Comments subject to moderation before publishing.