RGB Color in Property BackColor Report (1 Viewer)

Kronosds

New member
Local time
Today, 02:06
Joined
Jun 11, 2017
Messages
9
Hi there, My name is Daniel Solis live in the Paso Texas, I'm new in the forum , and I have some experience in Access.
I hope to contribute something in this forum and learn even more things.

This the problem I have, in my table "Master Color" I have four columns "Color, R, G, B" with the color real.

In a report I have two controls TxtColor and TxtLineColor, with data source in another query that contains the color (Text) "not table Master Color"
Example the text in the controls: White, Black, Blue, Dark Blue, Pink, Green, Light Green, Dark Green etc etc.

I need wich if the TxtColor or TxtLineColor control says for example white then look for the white text in the table "Master Color" and if it exists
then add the data from the R, G, B columns in the BackColor control property.

I got part of the objective but they are too many If Then, the ones that I have and I still do not finish with all the combinations. I think this can be simplified but I do not know how to achieve it, I hope you can help me.
Note: In my table I have about 300 different colors.

This is part the code:


Code:
Option Compare Database

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me.TxtColor = "Blue" Then
Me.TxtColor.BackColor = RGB(0, 0, 255)
Me.TxtLineColor.Visible = False
Else

If Me.TxtColor = "Blue Light" Then
Me.TxtColor.BackColor = RGB(135, 206, 250)
Me.TxtLineColor.Visible = False
Else

If Me.TxtColor = "Blue Dark" Then
Me.TxtColor.BackColor = RGB(0, 0, 139)
Me.TxtLineColor.Visible = False
Else

If Me.TxtColor = "Yellow/Blue" Then
Me.TxtColor.BackColor = RGB(255, 255, 0)
Me.TxtLineColor.BackColor = RGB(0, 0, 255)
Else

If Me.TxtColor = "Yellow/Blue Light" Then
Me.TxtColor.BackColor = RGB(255, 255, 0)
Me.TxtLineColor.BackColor = RGB(135, 206, 250)
Else

If Me.TxtColor = "Yellow/Blue Dark" Then
Me.TxtColor.BackColor = RGB(255, 255, 0)
Me.TxtLineColor.BackColor = RGB(0, 0, 139)
Else

If Me.TxtColor = "Yellow/Beige" Then
Me.TxtColor.BackColor = RGB(255, 255, 0)
Me.TxtLineColor.BackColor = RGB(245, 245, 220)
Else
More..more …more….more

I've even tried it with Select Case but it's the same is a very long process.

Let me know you coments please.

:banghead:
 

JHB

Have been here a while
Local time
Today, 11:06
Joined
Jun 17, 2012
Messages
7,732
Could you show some data from the table "Master Color", (printscreen)?
And could you explain w
hat end result you want to get.
... with data source in another query that contains the color (Text) "not table Master Color"

What is the different between the above query data and the
Code:
[FONT=Arial Narrow][SIZE=3][FONT=Arial Narrow][SIZE=3] in my table "Master Color" I have four columns "Color, R, G, B" with the color real. [/SIZE][/FONT][/SIZE][/FONT]


 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:06
Joined
Feb 19, 2013
Messages
16,610
not very clear about what you are asking or how it is supposed to work, but why not use a recordset and save all that code

dim rst as recordset
set rst=currentdb.openrecordset("SELECT * FROM tblMasterColors WHERE Color='" & me.txtColor & "'")
Me.TxtColor.BackColor =RGB(rst!R,rst!G,rst!B)
rst.close
set rst = nothing
 

Kronosds

New member
Local time
Today, 02:06
Joined
Jun 11, 2017
Messages
9
Hello, here is the screen:

The page do not let me upload images

The Back color should take it from the table "MasterColor", that's the idea but I'm doing it with many If Else.
 

Kronosds

New member
Local time
Today, 02:06
Joined
Jun 11, 2017
Messages
9
not very clear about what you are asking or how it is supposed to work, but why not use a recordset and save all that code

dim rst as recordset
set rst=currentdb.openrecordset("SELECT * FROM tblMasterColors WHERE Color='" & me.txtColor & "'")
Me.TxtColor.BackColor =RGB(rst!R,rst!G,rst!B)
rst.close
set rst = nothing

Great, Your proposed code has solved my problem....!

Thank you for you help

Kronosds :D
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:06
Joined
Sep 12, 2006
Messages
15,653
out of interest, if you want to analyse a colour the other way

so given RGB (1,50,180) = 11809281

to go the other way, and find the RGB values for 11809281

I wrote some fiddly stuff to successively divide by 256, use remainders and so on. I realised there must be an easier way, and just came across the Hex function

Hex(11809281) = B43201, which gives you the BGR values in Hex

B=Hex B4
G=Hex 32
R=Hex 01
 

Kronosds

New member
Local time
Today, 02:06
Joined
Jun 11, 2017
Messages
9
Great, yes it's correct what you say. I'll take it into account.

Thank you.

How I close the thread?
 

Users who are viewing this thread

Top Bottom