Solved

Access VBA - Matching Labels between reports

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

773 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