We help IT Professionals succeed at work.

SetProperty Foreground Colour

John Burdett
John Burdett asked
on
162 Views
Last Modified: 2017-03-14
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

John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

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
IT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
That is perfect thank you. Just one final question how is the long value of 11361562
derived
John TsioumprisIT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2019

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