[AccessD] Color Field on Continuous Form based on Field Value

Gustav Brock gustav at cactus.dk
Sun Sep 25 06:48:23 CDT 2022

Hi David

Yes. The simplest and fastest method is to write it directly with Put:

' Create bitmap file of one pixel having the specified RGB colour.
' 2022-09-25. Gustav Brock, Cactus Data ApS, CPH.
Public Function CreateBitmapFile( _
    ByVal FileName As String, _
    ByVal ColorR As Byte, _
    ByVal ColorG As Byte, _
    ByVal ColorB As Byte) _
    As Boolean

    ' White 1-pixel BMP file. the three FF bytes are the colour information.
    Const BitMapMask    As String = _

    ' Index for the colour information in the bitmap file.
    Const ColorIndexR   As Integer = 56
    Const ColorIndexG   As Integer = 55
    Const ColorIndexB   As Integer = 54

    Dim FileLength      As Integer
    Dim FileNumber      As Integer
    Dim Index           As Integer
    Dim Bytes()         As Byte
    Dim Success         As Boolean

    FileLength = Len(BitMapMask) / 2
    ReDim Bytes(0 To FileLength - 1)

    ' Build file bytes.
    For Index = LBound(Bytes) To UBound(Bytes) Step 1
        Bytes(Index) = CByte("&H" & Mid(BitMapMask, 1 + Index * 2, 2))
    ' Fill in colours.
    Bytes(ColorIndexR) = ColorR
    Bytes(ColorIndexG) = ColorG
    Bytes(ColorIndexB) = ColorB

    ' Write bitmap file.
    FileNumber = FreeFile
    Open FileName For Binary As #FileNumber
    Put #FileNumber, , Bytes()
    Close #FileNumber

    Success = CBool(Len(Dir(FileName, vbNormal)))

    CreateBitmapFile = Success

End Function

You can use my function RGBHex found here:

VBA.ModernTheme/ColourHandling.bas at master · GustavBrock/VBA.ModernTheme (github.com)<https://github.com/GustavBrock/VBA.ModernTheme/blob/master/ColourHandling.bas>

to build the filenames, like 9A690C.bmp


Fra: David Emerson<mailto:newsgrps at dalyn.co.nz>
Sendt: 25. september 2022 05:24
Til: 'Access Developers discussion and problem solving'<mailto:accessd at databaseadvisors.com>
Cc: Gustav Brock<mailto:gustav at cactus.dk>
Emne: RE: [AccessD] Color Field on Continuous Form based on Field Value

Hi Gustav,

Thanks for the link.  I appreciate you using the NZ flag in you demo 😊

I like your idea of creating the BMP files on the fly.  Do you have any code for doing this?


David Emerson
Dalyn Software Ltd
Wellington, New Zealand

-----Original Message-----
From: AccessD <accessd-bounces+newsgrps=dalyn.co.nz at databaseadvisors.com> On Behalf Of Gustav Brock via AccessD
Sent: Sunday, 25 September 2022 10:36 am
To: Access Developers discussion and problem solving <accessd at databaseadvisors.com>
Cc: Gustav Brock <gustav at cactus.dk>
Subject: Re: [AccessD] Color Field on Continuous Form based on Field Value

Hi David

You could write a tiny 1 x 1 pixel BMP file on the fly from a skeleton, only exchanging the three RGB bytes..
It is only 58 bytes starting with BM:


Here, the BGR colours to modify are the three bytes BE 92 70, in Access displayed as #7092BE.

Then, bind the created BMP files to a picture control on the form.
That can be done as shown in my article:

GustavBrock/VBA.PictureUrl: Download and display pictures directly from URLs (github.com)<https://github.com/GustavBrock/VBA.PictureUrl>


Fra: David Emerson<mailto:newsgrps at dalyn.co.nz>
Sendt: 24. september 2022 21:43
Til: AccessD<mailto:accessd at databaseadvisors.com>
Emne: [AccessD] Color Field on Continuous Form based on Field Value

Hi Listers,

I am familiar with using Conditional Formatting to color a field based on a fixed list of colors.

I have a continuous form where the user selects a different color for each record using the color picker and storing the color value in a field.  This color value is then used elsewhere in the program.

This means that the color can be any of hundreds of possible colours.

What I would like to do is have the background of the field (or something
else) colored in the color so the user can see what colors have been chosen across all the records showing on the continuous form.  Does anyone know a way of doing this?


David Emerson
Dalyn Software Ltd
Wellington, New Zealand


More information about the AccessD mailing list