Solved

How handle sub-reports for certain criteria

Posted on 2014-12-29
5
121 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
5 Comments
 
LVL 84
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:
SimonAdept 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:SimonAdept
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
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, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

757 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

20 Experts available now in Live!

Get 1:1 Help Now