Solved

Not printing subreport based on a criteria

Posted on 2004-08-26
8
334 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
 

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
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.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now