Print Main Report with selected subreports.

RichardP1978

Registered User.
Local time
Today, 19:04
Joined
Nov 14, 2006
Messages
89
I have one report, which has approxiamtely 10 subreports.

Sometimes it is not neccessary to print all the subreports off, just specific ones. I would like to have in my report list (I use the list box method) that when a user selects custom report, it brings up a form, where tick boxes can be selected to enable wether or not that subreport is included.

What I need some guidance on is how to make a subreport appear on the main report, based on the values of my frmCustomReportOptions if indeed it is possible to do.

Ta
 
Suppose you have a form called frmSelections and on that form you have a list box call lbxSubreports that contains the names of all the subreport objects in your report (the names of the objects, not the names of the subreports). I assume your list box is multi-select !

In your report, set the height of each subreport object to zero and ensure it is set to can-grow and also set the visible property to false. It's probably worth setting this stuff at the beginning of the code below so that your report remains usuable on it's own and also you ensure that it's set up right.

The you can put the following code in the On Open event for the report:

Code:
Dim varItem As Variant
For Each varItem In Forms.frmSelections.lbxSubreports.ItemsSelected

    Me.Controls(Forms.frmSelections.lbxSubreports.ItemData(varItem)).Visible = True
    
Next varItem
End Sub

This basically goes through each selection from the listbox and makes the corresponding section in the report visible. Note that here I've assumed that your subform objects are named exactly the same as in your list.

If you need an example let me know.

hth
Chris
 
THanks for that.

I adapted it slightly as it was easier to use an option group per subreport with simple yes/no options that users select and it works a treat. What is giving me a headache at the moment, is page breaks.

Before each subreport I had a page break. Now if I leave the page break in, I end up with blank pages, but if I remove it I end up with subreports appearing like a block and makes the data look messy as medication, care plans, risk assesments are really best on seperate pages. I have tried inserting page break in the header of the subreport and its doesnt really work properly.

Can page breaks be manipulated using VBA and if so is there a good source of info as I have tried a search but nothing really comes up that covers this.
 
no - is the answer on this- had the same problem myself
I have been told that page breaks are fixed (although I could be wrong)
 
I have controlled a page break in a report so that it would not break between the last item in the section and the section footer with the totals in it. I had the page break control at the bottom of the item section with its .visible set to false. Then when required I just set .visible to true to force the page break. I don't have that DB here at work but I can give you more detailed info tonight when I get home and can look at the archive copy of the DB.
 
Just driving around in car, I thought I wonder if the .visible can apply to a page break and it can.

I just did a quick test as Rabbie thought so too!

Me.EndOfFirstPage.Visible = False

and it works.

Now I will just tie it in to the option group Yes/No - True/False bit and I am away.
 

Users who are viewing this thread

Back
Top Bottom