Solved

How handle sub-reports for certain criteria

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

713 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