?
Solved

Access VBA - Matching Labels between reports

Posted on 2007-11-20
4
Medium Priority
?
638 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 2000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

765 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