Results 1 to 7 of 7
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    73

    Colours on a report

    I have a report with some data and is bound to a query.
    The report consists of the months and some calculated values under each month.

    The month headings contain the names of the month. Depending on criteria, I want the label containing the month name, to display a background color (Cyan). I use RGB(0, 255, 255). The code I use, as follows:

    Code:
        If Me("Label" & i).Caption = MonthName(i) And Month(TmpRptDate) < Month(Date) Then
            Me("Label" & i).Caption = Me("Label" & i).Caption & " " & Format(Date, "yyyy") + 1
            Me("Label" & i).BackColor = RGB(0, 255, 255)
        ElseIf Me("Label" & i).Caption = MonthName(i) And Month(TmpRptDate) >= Month(Date) Then
            Me("Label" & i).Caption = Me("Label" & i).Caption & " " & Format(Date, "yyyy")
        End If
    everything is fine, except that only the first label background is changed to Cyan. All the other labels that meet the first criteria, the backcolor stays white and is no changed. See picture below of the report. (All the months with |"2025" should be Cyan):



    Click image for larger version. 

Name:	ReportColor.png 
Views:	11 
Size:	13.7 KB 
ID:	51779

    Any suggestions?

    Thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,020
    Not showing much code there are you?

    Is that code within a loop incrementing i ?
    Are the labels all called Label1, Label2 etc?

    Walk your code with F8 and breakpoints and inspect the variables.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    73
    Hi Welshgasman,
    Yes, the code is within a For...Next loop.
    Label captions are named Label1, Label2...Label12

    I did step through the code with F8 and every time it executes the change of the color, but when the report is displayed, only the first label (Label1) has changed color to Cyan.

    I also tried running the code in the Detail_Format event as well as the PageHeaderSection_Format event, but with the same result.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,020
    Out of ideas then, sorry.
    You could post the DB with enough to see the problem. I work best like that for silly stuff.
    By that, I mean stuff that *should* work, but does not. Generally it is a silly error causing it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    A S MANN is offline Advanced System Analyst
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    India
    Posts
    163
    If you run code in On load event than it will run partially
    Place code in On Format of report .

  6. #6
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    73
    Hi,
    It seems the solution is to NOT use labels on the report. I replaced the labels with text boxes and now the ones that need to be a different back color, has indeed changed color.

    Thanks

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,020
    Quote Originally Posted by DC CS View Post
    Hi,
    It seems the solution is to NOT use labels on the report. I replaced the labels with text boxes and now the ones that need to be a different back color, has indeed changed color.

    Thanks
    Hmm, strange
    Well done for finding a solution.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Different Colours if Record is true
    By bishmedia in forum Reports
    Replies: 3
    Last Post: 06-08-2018, 02:10 PM
  2. Replies: 4
    Last Post: 05-20-2018, 02:19 PM
  3. Pdf changing colours when exporting reports
    By iancedwar in forum Reports
    Replies: 1
    Last Post: 06-12-2014, 03:41 AM
  4. colours in query
    By emcloa in forum Programming
    Replies: 7
    Last Post: 10-15-2012, 08:09 AM
  5. Reports and Colours
    By BarbT in forum Access
    Replies: 2
    Last Post: 10-08-2011, 07:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums