Selecting the background color of a form based on a criteria

G

Guest

I created a database for my company that has a field for countries (all of
them!). My boss wants to see in the form and report a different background
color for each country, for easy recognition. I have no idea how to do this.
The Conditional Formatting will allow me to at least have a tab in a
different color dependeing on the country, but you can only enter 3 and
obviously, there are more than 3 countries in the world. Does any one can
help me with this? I am a novice, so please, if you do know how to
accomplish this, give me the detailed instruction.

Thanks in advance!
 
F

fredg

I created a database for my company that has a field for countries (all of
them!). My boss wants to see in the form and report a different background
color for each country, for easy recognition. I have no idea how to do this.
The Conditional Formatting will allow me to at least have a tab in a
different color dependeing on the country, but you can only enter 3 and
obviously, there are more than 3 countries in the world. Does any one can
help me with this? I am a novice, so please, if you do know how to
accomplish this, give me the detailed instruction.

Thanks in advance!

This seems awfully silly, as though anyone will remember that color #
1852365 belongs to Swaziland and # 1952000 belongs to Angola!

In your report, code the Detail Format event ..... and, in your form,
code the AfterUpdate event of whatever control is used to select the
country as well as the Form's Current event:

Dim AColor as Long
AColor = GetColor([Country])
Me[Country].BackColor = AColor


Create a New Module:

Function GetColor(CountryIn as Text) as long
Dim ColorValue as Long
Select Case CountryIn
Case "Germany"
ColorValue = 16711935
Case "Great Britain
ColorValue = 8421631
Case "Italy"
ColorValue = vbGreen
' etc.
Case Else
ColorValue = 12345678 'Whatever default color you want.
End Select
GetColor = ColorValue
 
G

Guest

Thank you Fred, however, I tried it and is telling me that "user-defined type
not defined". As I mentioned before I am a novice (extremely). I am
learning most of it by myself and most of the mumble jumble that you guys
"talk about" on this forum is not too clear for me. Could you tell me what
may I be doing wrong to get this message? I followed your instructions to
the dot I created the Module, the AfterUpdate event code, etc

Thanks

fredg said:
I created a database for my company that has a field for countries (all of
them!). My boss wants to see in the form and report a different background
color for each country, for easy recognition. I have no idea how to do this.
The Conditional Formatting will allow me to at least have a tab in a
different color dependeing on the country, but you can only enter 3 and
obviously, there are more than 3 countries in the world. Does any one can
help me with this? I am a novice, so please, if you do know how to
accomplish this, give me the detailed instruction.

Thanks in advance!

This seems awfully silly, as though anyone will remember that color #
1852365 belongs to Swaziland and # 1952000 belongs to Angola!

In your report, code the Detail Format event ..... and, in your form,
code the AfterUpdate event of whatever control is used to select the
country as well as the Form's Current event:

Dim AColor as Long
AColor = GetColor([Country])
Me[Country].BackColor = AColor


Create a New Module:

Function GetColor(CountryIn as Text) as long
Dim ColorValue as Long
Select Case CountryIn
Case "Germany"
ColorValue = 16711935
Case "Great Britain
ColorValue = 8421631
Case "Italy"
ColorValue = vbGreen
' etc.
Case Else
ColorValue = 12345678 'Whatever default color you want.
End Select
GetColor = ColorValue
 
F

fredg

Thank you Fred, however, I tried it and is telling me that "user-defined type
not defined". As I mentioned before I am a novice (extremely). I am
learning most of it by myself and most of the mumble jumble that you guys
"talk about" on this forum is not too clear for me. Could you tell me what
may I be doing wrong to get this message? I followed your instructions to
the dot I created the Module, the AfterUpdate event code, etc

Thanks

fredg said:
I created a database for my company that has a field for countries (all of
them!). My boss wants to see in the form and report a different background
color for each country, for easy recognition. I have no idea how to do this.
The Conditional Formatting will allow me to at least have a tab in a
different color dependeing on the country, but you can only enter 3 and
obviously, there are more than 3 countries in the world. Does any one can
help me with this? I am a novice, so please, if you do know how to
accomplish this, give me the detailed instruction.

Thanks in advance!

This seems awfully silly, as though anyone will remember that color #
1852365 belongs to Swaziland and # 1952000 belongs to Angola!

In your report, code the Detail Format event ..... and, in your form,
code the AfterUpdate event of whatever control is used to select the
country as well as the Form's Current event:

Dim AColor as Long
AColor = GetColor([Country])
Me[Country].BackColor = AColor

Create a New Module:

Function GetColor(CountryIn as Text) as long
Dim ColorValue as Long
Select Case CountryIn
Case "Germany"
ColorValue = 16711935
Case "Great Britain
ColorValue = 8421631
Case "Italy"
ColorValue = vbGreen
' etc.
Case Else
ColorValue = 12345678 'Whatever default color you want.
End Select
GetColor = ColorValue

Assuming you accurately entered all the code, in their proper places,
I would suspect you have a reference problem.

Open any module in Design view (or click Ctrl + G).
On the Tools menu, click References.
Click to clear the check box for the type library or object library
marked as "Missing:."

An alternative to removing the reference is to restore the referenced
file to the path specified in the References dialog box. If the
referenced file is in a new location, clear the "Missing:" reference
and create a new reference to the file in its new folder.

See Microsoft KnowledgeBase articles:
283115 'ACC2002: References That You Must Set When You Work with
Microsoft Access'
Or for Access 97:
175484 'References to Set When Working With Microsoft Access' for
the correct ones needed,
and
160870 'VBA Functions Break in Database with Missing References' for
how to reset a missing one.

For even more information, see
http://members.rogers.com/douglas.j.steele/AccessReferenceErrors.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top