problem hiding controls in a form contained within a subreport

CraigDolphin

GrumpyOldMan in Training
Local time
Today, 12:00
Joined
Dec 21, 2005
Messages
1,582
I am working on a fisheries regulations database. I have a report summarizing basic regulation information (date filed etc) which contains a subreport that details which gear type(s) are being covered in the regulation. Within this subreport, I have a (sub)form (generic_conditions) that lists many kinds of gear restrictions etc.

I have used the on_current event of the form to make controls with no data invisible. This is necessary since different conditions apply to different gear types (eg, net mesh size is irrelevant if you're using a fishing pole). In the interests of saving space on the report, I have overlapping controls such that net fishing conditions occupy the same space on the form as crab pot conditions. When I open the form directly, all works as it should. Empty controls and their labels are not displayed.

However, when I open the report, the form shows up with the right information for the specific gear type and regulation, but all controls are visible and therefore overallping and impossible to read. If I switch the default Visible property of each control on the form to 'no' then none of the conditions appear even if data is present.

Here's an example of the code setting the visible property for one of the controls inside the on_current event of the form.

Code:
If Me.FishHooksizes & "" = "" Then
Me.FishHooksizes.Visible = False
Else: Me.FishHooksizes.Visible = True
End If

It seems like the report is ignoring the on_current event of the subform. I've tried using the code in the on_open event of the main report, or of the form's parent subreport but have not had any success. I keep getting errors with my code when I try that (yes, I changed the link to the controls to match the path from the report/subreport when I made that change)

I'm stumped. Anyone offer me some insight into why this is happening?

Appreciate any replies. :)
 
I could be wrong but I don't think you can have a form in a report
 
Well, the form appears in the report and the correct data is shown in the form 'controls' for each section of the report. It's only the visibility issue that I'm having trouble with. But perhaps I'm trying to force a square peg in a round hole. Hmm.
 
Are you talking about a form or Report, a form used as a subReport is a subReport and not a form, there is no Current_Event for a subReport or Report.
 
Hi Rich. Sorry for the slow reply. Had to take a couple of days away from work due to a death in our family.

I was using the form as a subreport. I thought that opening the form separately and running the code in the on-current event of the 'form' would work. I guess I was wrong. Can you suggest any other way to achieve what I want?
 
If I remember correctly, if you format the box / label to appear / dissappear, that will format for that box across ALL records. It will turn them ALL off or ALL on on ALL records. It will work great if you only return ONE record, but when you are making a list of records, it won't.

Same thing happens with forms. To see this work, set up the form to view multiple records on, not a single form / record. As you click on each record, the boxes will appear / disappear for all records based on the conditions of the current record :P
 
The problem with setting each control's default visibility is that for some records the control should be visible, and for other records that control should not be visible. I can make the controls appear-disappear when viewing multiple records when viewing the form as a 'form' (using code in the On_Current event). However, when I embed this 'form' into a report, the on-current code no longer causes the controls to appear as needed.

I will try using the detail event for the subreport as Rich suggested. Thanks for both replies.
 
You need to refer to the sub-form or sub-report in the following manner

Forms!frmParent!subForm.Form!FishHooksizes.Visible = True

Reports!rptParent!subReport.rpt!FishHooksizes.Visible = True

ie the form or report collection
then the form or report name
then the subform or subreport container
then the form or report in the container
then the control
 

Users who are viewing this thread

Back
Top Bottom