Solved

Not printing subreport based on a criteria

Posted on 2004-08-26
8
363 Views
Last Modified: 2008-03-10
i have a report containing subreports. is it possible NOT to print a subreport withhin a report based on a employee id#??

for ex, i dont want The project subreport to show up when im printing report for empid#100.? Pls advice.
0
Comment
Question by:thinker388
  • 5
  • 3
8 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 500 total points
ID: 11907903
Yes it is. You can use the OnFormat event of the report section to do this. For example:

If Me!txtEmployeeID=100 Then
   Me!MySubReportControl.Visible=False
End If

txtEmployeeID in this case is the control that contains the EmployeeID (and I have assumed it is in the same section as the subreport). MySubReportControl is the name of the control that the subreport is contained in, not the subreport itself.

You may find it better to have a yes/no field in your table to determine if the subreport should be printed. You can then put this field into a hidden control and use say:
If Me!chkPrintSubreport=False Then
instead.

For best results, set the subreport to be of absolutely minimal height, and set the CanGrow property to yes.
0
 

Author Comment

by:thinker388
ID: 11907959
"If Me!txtEmployeeID=100 Then
   Me!MySubReportControl.Visible=False
End If"

well the empid doesnt get printed but its in the query on which the report is based.  so can i just reference the query?

"MySubReportControl is the name of the control that the subreport is contained in"...sorry i didnt get that...is the subreport contained within a control? r u talking abt the main report consisting of all the subreports?
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11908001
Subreports and subforms live inside subreport and subform controls. Click on a subreport in design view. Bring up the Properties (View->Properties).

Look in the Other page at the Name property. This is the name of the control. Look in the Data page, at "Source Object". That is the name of the actual report inside the control. These two are often the same (especially if you create it automatically), but might not be.

As fpr the empid not being printed, just put it into a textbox on your report, and set the textbox's Visible property to No.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:thinker388
ID: 11908092
this is the code:

If [Forms]![frmReport]![txtemp] = "14564" Then
    Me![Project B-Jerry].Visible = False
End If

it errors out saying, access cant find the field Project B-Jerry referrred in my expression. I got the "Project B-Jerry " from Name property from the Other page. BTW my source object and the name property have diff values.
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11908118
Whereabouts do you have the code running? Also, what is your SourceObject property (just to double check)?
0
 

Author Comment

by:thinker388
ID: 11908133
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If [Forms]![frmReport]![txtemp] = "14564" Then
    Me![Project B-Jerry].Visible = False
End If

End Sub


sourceobject: Report.rptTasks
0
 

Author Comment

by:thinker388
ID: 11908143
oooh wait...got it..i was putting it on format event of the subreport not in the main report itself
0
 

Author Comment

by:thinker388
ID: 11908157
works a treat now..thanks much :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

685 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