Solved

How handle sub-reports for certain criteria

Posted on 2014-12-29
5
128 Views
Last Modified: 2015-01-02
I have a report that will have up to five different sub-reports.  Only one of the sub-reports will be needed based on a field on the main report.  That field name is "txtInterviewTypeID".   I am trying to use the following code in the oncurrent event of the main report but it doesn't seem to be driving which sub-report to make display.

Note that I have the sub-reports on top of each other in the detail section of the main report if that matters.

    If Me.txtInterviewTypeID = 1 Then
        Me.TechInterviewQuestionnaire.SourceObject = "subrptInterview1"
    End If

    If Me.txtInterviewTypeID = 2 Then
        Me.TechInterviewQuestionnaire2.SourceObject = "subrptInterview2"
    End If

    If Me.txtInterviewTypeID = 3 Then
        Me.TechInterviewQuestionnaire3.SourceObject = "subrptInterview3"
    End If

Open in new window

0
Comment
Question by:SteveL13
[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
5 Comments
 
LVL 85
ID: 40522517
Reports don't have OnCurrent events, and you can't change these sorts of things in a report except in the Open event, so move your code to that event.

So can you show more than one subreport at a time? If not, then you only need one control, and you would change the Sourceobject of that control based on the value in txtInterviewID:

Select Case Me.txtInterviewTypeID
  Case 1
    Me.YourSubformControl.sourceObject = "subreport1"
  Case 2
    Me.YourSubformControl.sourceObject = "subreport2"
End Select
0
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40522518
Try putting your code in the  "on format" event of the detail section of main report:

if that doesn't work, rather than setting the source object for the relevant subreport, just switch their visibility, as in:

Again, code to go in the On_Format event of the detail section of the main report
  If Me.txtInterviewTypeID = 1 Then
        Me.TechInterviewQuestionnaire.visible=TRUE
        Me.TechInterviewQuestionnaire2.visible=FALSE
        Me.TechInterviewQuestionnaire3.visible=FALSE
ELSE IF Me.txtInterviewTypeID = 2 Then
        Me.TechInterviewQuestionnaire.visible=FALSE
        Me.TechInterviewQuestionnaire2.visible=TRUE
        Me.TechInterviewQuestionnaire3.visible=FALSE
ELSE IF Me.txtInterviewTypeID = 3 Then
        Me.TechInterviewQuestionnaire.visible=FALSE
        Me.TechInterviewQuestionnaire2.visible=FALSE
        Me.TechInterviewQuestionnaire3.visible=TRUE
    End If

Open in new window

0
 
LVL 30

Expert Comment

by:hnasr
ID: 40522866
I go with Scot's comment. It uses one subreport and modifies its SourceObject  as you partly mentioned in your code. The code is used in the Form Open event.

SimonAdept's comment may work, but you may need to deal with extra blank space.

Try and give your feedback.
0
 

Author Comment

by:SteveL13
ID: 40523557
Using Scott's comment the report gets stuck on...
Select Case Me.txtInterviewTypeID  (RT error 2427. "You entered an expression that has no value")
I did put the suggested code in the onopen event of the report.

Simon's suggestion is working and there is no extra space probably because I put the sub-reports on top of each other in the detail section of the main report.
0
 
LVL 18

Expert Comment

by:Simon
ID: 40523642
Cool. I suggested what I did in case you had different sized sub-reports for the different interview types. Good use of "can grow" and "can shrink" can also help avoid blank spaces.

I also assumed that you might be printing a whole set of records with varying interview types, so you need an event that fires for the detail section of each record as the report is rendered.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

729 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