SSRS : Passing parameters to a subreport - sql-server

I have a report containing 3 different subreports (each accepting a different set of parameters), and only displaying one of them depending on the value of a parameter.
When I choose to display any one of them, it gives me the following error:
Error: Subreport could not be shown
I need to have this visibility parameter let me decide which subreport I wanna see, then have the ability to pass the right parameters to that chosen subreport. Is there any way of doing this ?
Here are some screenshots:
https://imgur.com/a/n8bKny8

OK, I understand how you have structured the report now. I think the approach is a little wrong. It's like you are mixing two appraoches.
If you are trying to make this like a "Wizard", step-by-step approach, then you could simply change your main report to have 3 text boxes, one for each report, with a "Go to Report" action set. This will simply open the 'subreport' (it won't technically be a sub-report now) and then you can select parameters as normal. Optionally, format the textbox and make it look more like a button.
The other approach if you want to do this all in a single step would be to change the main report have all the parameters that are required across all subreports and allow the user to set them there (in the main report). These parameters can then be passed to the subreport via the subreport properties (parameters tab).
It really depends on the user experience you want to achieve but the simplest option would be the first option.
If this does not help, I'll try to post an example later tonight.

Related

is it possible to make parameters in sub-report visible in SSRS?

I have a main report with parameters and passing those parameters to sub-report.
But when sub-report displays - all parameters are hidden in report manager, so no way to choose any parameters in sub-report.
My question is: even though you passing parameters from main report to sub-report, are there any ways to still see the parameters in sub-report and be able to choose values and run this sub-report with different value parameters?
Sound like you need to have Cascading parameters. I'm not sure I can understand the use case for your current setup, but it looks like you are running a report to see certain records, then choose another parameter to further narrow down your results.
You can have multiple drop down parameters where based upon the first parameter you choose, it will automatically filter the second parameter to show you values based on the first. These parameters would reside on your main report, and possibly eliminate the reason for the sub-report?
https://msdn.microsoft.com/en-us/library/dd255197.aspx
I assume you realize that you can expand and collapse the parameters pane in the report viewer. I also assume you are referring to a drill through report (as indicated by the settings screen you've included), despite your comment to the contrary.
In your screenshot, you have the parameters pane collapsed, which I believe is the default behavior when opening a drill through report. To my knowledge, this default can't be changed on a setting in the rdl itself, but users can be easily trained to simply expand the pane after opening the report.

How to dynamically populate a report?

Hopefully this is the last question I have about Access since I will be done working with it very soon.
I currently have a report that is generated from a form that is filled out when a "Run" button is pressed. A database primary key is searched for and the form is populated. When the user clicks a "Print" button, a printable report is generated, being populated by data from that form. All of that was easy.
Now, in the form, there is a single list box. That list box displays results for a transaction type depending on which transaction type is clicked. For example, clicking "Purchase" will yield all customers who have purchased something in the list box, and clicking "Sold" will yield all customers who have been sold something in the list box. There are many more transactions than those two, but that does not matter for the purpose of this question.
What I need to do is make the contents of that list box (which is populated by a query in VBA) for every transaction type appear on the printable report.
So for example, the report might look something like this:
Purchases:
John
Cindy
Alex
Sold:
Matt
Steven
John
Rob
Does anyone know a simple way to do this? I can vaguely think of how I might do this, but it is complex and I don't know the exact functions I would need to use. Basically I was thinking I would run the query that populates the list box, but then parse through each result in a while loop, and display it on the report.
Thank you in advance for any help!
A Report is a fairly static object in comparison to a Form. To dynamically change the data that is displayed in a report you would typically use the Where argument for OpenReport, usually on a button press and reading some value from a control on the currently active form:
DoCmd.OpenReport "rptName", acViewPreview, , "SomeField=" & frmName!ctlName
If the value on the form is a string then it needs to be surrounded with apostrophes:
DoCmd.OpenReport "rptName", acViewPreview, , "SomeField='" & frmName!ctlName & "'"
A report also has a Filter property that you might use, or you can programmatically set its RecordSource. The first option is the most common, and the easiest.
If the report has a listbox then you would typically modify its RowSource, using a query with a criteria that refers to a control on your form. But I would question why this is necessary, as the listbox would have no relation to the rest of the data in the report.
If you are talking about dynamically changing what appears on the report - moving and hiding controls, etc. - then this is a different question. You would need to first open the report in Design View. This is unusual and rarely necessary. Typically, you would create a separate report, perhaps copying the original report, and just use the button to decide which report to display. (There are Report Events that can be used to hide, or move, controls on the report - OnFormat, for example - that wouldn't require the report to be opened in Design View, but I don't think this is what you are looking for.)
Assuming that the report will be created using the recordset that was used to create the form, you could join the recordset that populates the listbox to the recordset that populates the rest of the form. If you, say, LEFT JOIN the recordset for the list box to the recordset for the form on the transaction type, the resulting recordset should have every thing you need to create the report required.
If the report needs to chabnge its format based on the transaction type, try using the OnOpen and OnClose Events for the report and the OnFormat Event for the Detail sections. I have some experience with reports like that. If you need more help with the events, add comments with some specific detail and I can probably make useful suggestions.

Page header on two subreports of different length side by side (ActiveReports)

I have a report that contains two main subreports, each taking a vertical half of the page, so they go side by side. Each has their own page header which I emulate by using a groupheader and seting the RepeatStyle property to OnPageIncludeNoDetail. However, both may have a different length, and I want the rightmost subreports to show the page header even if the report has no more data to show. In other words, if the right subreport takes less pages than the left report, I need for it to keep printing the header data on each page until the leftmost report ends. This is failing right now because once the subreport on the right is finished, it assumes the header needs not to be printed anymore.
I've tried adding a page break at the bottom of the subreport on the right, but as I don't know how many pages either of the subreports have, I don't know whether I should enable it or not until too late (or at least I didn't find a way to do so).
BTW, I'm using AR3 but upgrading to AR7 is supposed to occur at some point of the future...
Once a subreport ends and is no longer being put on each page it won't be possible to get it's page header rendered on the next page. I think your best option here is to use a parent report to include the pageheader information as only a parent report will continue to render as long as either one of the subreports render.
Note: It doesn't need to be the same parent report you're using now, but you could be another in between the current parent report and the two subreports to deal with the page headers.
I would suggest that you use groupheader/footer in the subreports instead of pageheader/footer and set the repeatstyle property of groupheader to OnPage.. Pageheader/footer in subreports are not supported because Subreports are not page aware.
The pageheader/pagefooter of the main report with render fine as scott mentioned.
I found a way to do this although it is not flawless. But the problem may be only on AR3 and hopefully fixed on AR7.
What I did was move the right subreport's header on a separate header of the master report. So now the master report has a page header, then the new group header (let's call it ghPage), and lastly the group header that originally contained both subreports.
Then, I set ghPage's property UnderlayNext to true, taking care to leave the necessary blank space to let ghPage fit in.
That's it, and it seems to work, but... when the left side subreport takes less than the right's page header high, this last section appears cropped to the left's height.

Drilldown Reports

Help
I am attempting to create a drill down report using report server and Visual Studio 2005.
I have been able to create a tree structure, but the original report looks like it opened a new report. (Crystal Report)
This was done by the report hiding all other data apart from the drilled data and the data title.
I can’t seem to be able to do this at the moment or seem to find any help online to do what is needed.
Does anyone know how I can do this or know of any material online that could help?
Thanks
i can think of two different ways to interpret your question. 1. you want a table in a report that, when the user clicks on a specific row, drills down into the report. 2. you want a report that, when a user clicks on certain rows, it opens up another report that's a drill down of the data. for option one, read my blog here and tell me if that's what you're looking for.
Not sure which way you're asking, so I'll list both.
For all your data on a single report which is grouped you can right click on the row indicator on the table and select properties, then visibility. Inside visibility you should see a checkbox with "Display can be toggled by this item" then the dropdown will have a list of textboxes that are on the report. Just select the one you want to control the drilldown.
The alternative way is through report actions, which you create a separate report with or without parameters, and select the textbox and choose properties, goto action, select "Goto Report" then select the report to drill down to, and add your parameters.
Hope this helps.

Question about adding controls to a winform

In .NET Winforms, if I have some code which does something such as execute a stored proc against a SQL Server but I do not know how many parameters there are, can I add more controls to the form with the controls appearing straight away?
Thanks
Not sure exactly what you're asking here, but you can always add controls to a form dynamically. So, for example, if your code can determine that a stored procedure requires three string parameters, you could dynamically add three text boxes (plus three labels) to your form to allow users to enter values for these three parameters.

Resources