Avatar of John Burdett
John Burdett
 asked on

SetProperty Foreground Colour

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
Microsoft Access

Avatar of undefined
Last Comment
John Tsioumpris

8/22/2022 - Mon
John Tsioumpris

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

ASKER
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
ASKER CERTIFIED SOLUTION
John Tsioumpris

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
John Burdett

ASKER
That is perfect thank you. Just one final question how is the long value of 11361562
derived
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
John Tsioumpris

I saw it in the watch window....