Skip to content

Creating Color Constants

How to add new color constants.

Q:  James T. writes:  “I need to use certain colors for the back color of controls (I am changing the color from code on a report’s Detail section Print event procedure).  The VB color constants enum only has a few colors (vbRed, vbBlue, etc.).  How can I add to this group, so I can easily reference the colors I want to use?”

A:  In Access, this is quite easy (though not very intuitive).  First, select the back color you want for a control on a form.  Use the Build button next to the BackColor property to select the color from the drop-down color palette, or create a custom color.  Switch to form view to see what the color looks like (some colors look different in design view and form view).  When the color is to your liking, copy the color number to the clipboard with Ctrl-C.

Then, in the Declarations section of a standard module, create a public constant for the color, and paste in the color numeric value, like this:

Public Const vbPink = 16744703

 

Then you can use the constant vbPink just the same as one of the built-in color constants, anywhere you want to set a color property.

About this author

Office 2024 - all you need to know. Facts & prices for the new Microsoft Office. Do you need it?

Microsoft Office upcoming support end date checklist.