Solved

Access VBA - Matching Labels between reports

Posted on 2007-11-20
4
633 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 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