[AccessD] Color Field on Continuous Form based on Field Value
David Emerson
newsgrps at dalyn.co.nz
Sun Sep 25 11:01:26 CDT 2022
Thanks very much.
-----Original Message-----
From: AccessD <accessd-bounces+newsgrps=dalyn.co.nz at databaseadvisors.com> On Behalf Of Gustav Brock via AccessD
Sent: Monday, 26 September 2022 12:48 am
To: Access Developers discussion and problem solving (accessd at databaseadvisors.com) <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
Yes. The simplest and fastest method is to write it directly with Put:
<code>
' 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 = _
"424D3A000000000000003600000028000000010000000100000001001800000000000400000000000000000000000000000000000000FFFFFF00"
' 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))
Next
' 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
</code>
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
/gustav
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?
Regards
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:
000102030405060708090A0B0C0D0E0F
--------------------------------
424D3A00000000000000360000002800
00000100000001000000010018000000
00000400000000000000000000000000
000000000000BE927000
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>
/gustav
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?
Regards
David Emerson
Dalyn Software Ltd
Wellington, New Zealand
--
--
AccessD mailing list
AccessD at databaseadvisors.com
https://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
More information about the AccessD
mailing list