Solved

Access VBA - Matching Labels between reports

Posted on 2007-11-20
4
635 Views
Last Modified: 2008-02-01
Hi,
I am trying to match the labels in two reports that I have. I have a report that opens, once this is open a piece of code in that report is run. This will look at another report that is already open, compare the captions of the two reports labels, and if they match set the two backcolors to match. However, this does not seem to be working. I get no errors, but it is not working? My code I have tried to use is attached.

Thanks
For Each ctl In Me.Controls
        If ctl.ControlType = acLabel Then
            For i = 11 To 20
                If ctl.Caption = Reports!rpt_ViewResults!("Label" & i).Caption Then
                   ctl.BackColor = Reports!rpt_ViewResults!("Label" & i).BackColor
                End If
            Next
        End If
    Next ctl

Open in new window

0
Comment
Question by:andyb7901
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 20318462
Do you have any basis for believing this to be possible?
I have never wanted to do anything like this so I'm not 100% sure that it is not possible, but my instinct is that once a report has been rendered it is done with and you can't then affect its appearance.
0
 
LVL 3

Accepted Solution

by:
pmctrek earned 500 total points
ID: 20318612
This is possible but it needs to be in the detail_format() event and be warned.. this takes a lot of time to process as the event is called for every line in the report.  If the labels you need to colour are in the page header and not the details, then its not too bad as you need to put the code into the pagePageHeaderSection_Format() event instead of the detail_format and this is only called once per page.  One of my reports colours any batch that has a value greater than 5000 the code is below.

The code also adds a line number to the report.
Option Compare Database
Dim intRecordCount As Integer
 
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    txtReportLine.Caption = intRecordCount + 1
    intRecordCount = intRecordCount + 1
    If BatchValue > 5000 Then
        RevBatch.BackColor = vbRed
    Else
        RevBatch.BackColor = vbWhite
    End If
End Sub
 
 
Private Sub Report_Open(Cancel As Integer)
 intRecordCount = 0
End Sub

Open in new window

0
 
LVL 3

Expert Comment

by:pmctrek
ID: 20318622
Also.. check that the backeffect is not set to transparrent.. it needs to set to Normal otherwise the code could be working fine but you cant see it if the background is transparrent.. this caught me once or twice!

Paul
0
 
LVL 77

Expert Comment

by:peter57r
ID: 20318649
Ah - misread the Q.
I thought you were trying to change the background in the other report.  Sorry.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question