SetProperty Foreground Colour

John Burdett
John Burdett used Ask the Experts™
on
I am trying to set label colours dependant on a value set by a user in a table.

When I assign for example RGB(26, 93, 173) to variable teamcolour. SetProperty works fine with this and makes the font blue. However when I fetch the same value from a table the font is black. I have tried Dlookup  and recordsets. In both cases the variable holds the value RGB(26, 93, 173) but appears not to use it or evaluates it to 0. Why is this?

 The code I am using is as follows:
    Dim dbsPlayerProfile As DAO.Database
    Dim rstOwnerTeam As DAO.Recordset
    Dim TeamColour As String
    Dim ColourTeam
 
   Set dbsPlayerProfile = CurrentDb
   Set rstOwnerTeam = dbsPlayerProfile.OpenRecordset("Owner Team")
 
   rstOwnerTeam.MoveFirst
   TeamColour = rstOwnerTeam!Colour.Value

    DoCmd.SetProperty "Label0", acPropertyForeColor, TeamColour
    DoCmd.SetProperty "League", acPropertyForeColor, TeamColour
    DoCmd.SetProperty "Owner Team", acPropertyForeColor, TeamColour

rstOwnerTeam.Close
' This produces black font

-------------

When I set the value in the code however as follows:

    Dim TeamColour
    DoCmd.SetProperty "Label0", acPropertyForeColor, TeamColour
    DoCmd.SetProperty "League", acPropertyForeColor, TeamColour
    DoCmd.SetProperty "Owner Team", acPropertyForeColor, TeamColour

' This produces blue
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Commented:
I am under the impression your rst doesn't return the correct value...can you give a sample?

Author

Commented:
The Table Owner Team has only one record and contains a field colour which hold the value RGB(26, 93, 173) and this is displayed when I use the msgbox

This is all the code I was using

    Dim dbsPlayerProfile As DAO.Database
    Dim rstOwnerTeam As DAO.Recordset
    Dim TeamColour As String

 
   Set dbsPlayerProfile = CurrentDb
   Set rstOwnerTeam = dbsPlayerProfile.OpenRecordset("Owner Team")
 
   rstOwnerTeam.MoveFirst
   TeamColour = rstOwnerTeam!Colour.Value


 
   
           
    DoCmd.SetProperty "Label0", acPropertyForeColor, TeamColour
    DoCmd.SetProperty "League", acPropertyForeColor, TeamColour
    DoCmd.SetProperty "Owner Team", acPropertyForeColor, TeamColour
   
    MsgBox (TeamColour)

  rstOwnerTeam.Close
Software & Systems Engineer
Commented:
I guess you are reading it as a set of integers or a string....but RGB is a long so you must provide the correct Long interpretation....
So for example (this will give a nice blue color)
DoCmd.SetProperty "Label0", acPropertyForeColor,11960589

Open in new window

EDIT i just saw your RGB values so this what you need
DoCmd.SetProperty "Label0", acPropertyForeColor,11361562

Open in new window

Author

Commented:
That is perfect thank you. Just one final question how is the long value of 11361562
derived
John TsioumprisSoftware & Systems Engineer

Commented:
I saw it in the watch window....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial