Solved

How handle sub-reports for certain criteria

Posted on 2014-12-29
5
129 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

628 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