Solved

Access VBA - Matching Labels between reports

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now