Solved

How handle sub-reports for certain criteria

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

770 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