Solved

Passing a boolean flag to crystal reports

Posted on 2001-06-21
15
1,626 Views
Last Modified: 2007-12-19
How can you pass a value from visual basic to crystal reports?  I want to be able to check whether or not a certain condition exists, based on some data from a recordset.  If the condition is meet, then I want to display a header of the report, otherwise I want to surpress it.  

Can the above be done from within crystal reports, if so please explain how.

Thanks
0
Comment
Question by:jpresser
  • 8
  • 7
15 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6216580
What version of Crystal are you using.  The API continues to evolve.  Short answer to your question is yes.  Long answer is Why?

In Crystal you can right click on the header in question and put a conditional formula in for Suppression of the section.  Can't you make use of the Crystal formulas to determine whether or not the condition is true and suppress within the report?

If you want more info on either - please supply CRW version, and some kind of example of the data in question and which approach you want to explore.

Best Regards
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6216583
JPresser

Please clear up the outstanding open questions showing in your profile.
0
 

Author Comment

by:jpresser
ID: 6219165
I am using crystal 8.0.  I can not get the formula in the header to work because I need to be able to check the following condition in the record set:

if {PDTItemQ.strLeadType} <> "VDD" AND {PDTItemQ.strDeviceType} = "Brady" then
  TRUE (Meaning surpress)

Otherwise False

This works if the first record in the record set meets the above condition.  The problem is if the first record does not meet the condition, but another record does.  The header will not be shown, when it needs to be or visa versa.

If any of the records meet the Otherwise false, then I want to display the header. How can I test the record set to know whether or not to display the header?


0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6219210
So you are trying to print the header if any record in that group's details section has LeadType = VDD and DeviceType <> Brady.  If all records in the group match that condition you do not want the header to print.  

Is that correct?
0
 

Author Comment

by:jpresser
ID: 6219257
If any record in the record set meet the condition  that DeviceType = Brady and that LeadType = VDD then I want the header to print.

If all records do not meet the above condition then I want to surpress the header.
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6219564
Right click on the header you wish to suppress and choose Format Section from the menu.  Click on the X-2 button next to Suppress (No-Drill Down).  This will put you in the formula editor.  Put the following formula in and save it:

WhileReadingRecords;
if {PDTItemQ.strLeadType} = "VDD" AND {PDTItemQ.strDeviceType} = "Brady" then
  false
else
  true

This will cause the group header to print ONLY when LeadType is VDD and DeviceType is Brady.  The directive WhileReadingRecords forces this formula to be evaluated after the records have been read because we are in a header, but before the page is printed.

0
 

Author Comment

by:jpresser
ID: 6219639
The formula did not work.  It still only works if the first record meets the condition.  

I should add that the header is in a subreport.  I don't know if this matters.  I am new to crystal reports, so I don't know what methods are available to it.

Please help

Thanks
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6219669
Try
WhileReadingRecords;
if ({PDTItemQ.strLeadType} = "VDD" AND {PDTItemQ.strDeviceType} = "Brady") then
 false
else
 true

I added parentheses


The header is in a subreport and the detail data is in the main report?  Or is all data part of the subreport?  A subreport is pretty much a self-contained report that just happens to be printed as part of another.
0
 

Author Comment

by:jpresser
ID: 6219681
The data and header are in the subreport.  The selection formula in the detail selection works as I want it to.  So I see the data without the header.
0
 

Author Comment

by:jpresser
ID: 6219693
The parentheses did not work.  Same result as last time.  May be if we do a query in visual basic, and pass the flag to crystal as to whether or not to display the header?

I don't know how to pass a value from vb to crystal reports.  
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6220023
The problem is that you are passing detail records in the recordset from VB.  CR is what is performing the grouping action on that recordset.

The process to pass values into CR from VB is to define a formula in CR.  In VB prior to calling the displayreport or printreport method, you change the value of the formula like:

crystalreport.formulas(0) = "New Formula in CR Syntax"

The formula could be as simple as a 0 or a 1 or some text string.

To do it that way however would require you to step through the recordset before opening the report and perform the computation on each group, updating some field in the recordset (for each record) as you move through the groups.  

You can dynamically change values in the report engine as it (CR) reads and processes the data, but that's a lot of work.

Just to be absolutely clear, are we talking about
1.  A header in the Report Header section of the sub-report
2.  A header in the Page Header section of the sub report
3.  A header in a group header section of the sub report
4.  something else?
0
 

Author Comment

by:jpresser
ID: 6220083
We are talking about the Report Header (Section 1) of the sub report.

I am thinking of just perfoming a sql statement on the on the pdtItemQ table for the given patient ID.  Here is what I am thinking

Select Count(*) FROM ptdITEMQ WHERE pat_id = ID AND strDeviceType = 'BRADY' AND strLeadType = 'VDD'

if count = 0 then
   Flag = true
else
  Flag = false
end if

Now send this Flag to crystal reports to either print the header or supress it.

This logic would be done before crystal reports is involked.

Is this possible.  If so please give me the crystal reports code needed to make it happen.

If it is not possible, and a stupid way of doing things, please tell me how to do what is needed.

Thanks for your help
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6220778
This is not possible that I know of.  The reason is that CR is a multi-pass reporting tool.  In other words, CR will make as many passes through the data as it requires to process your report.  A sub report adds a layer of complexity because, generally, a sub report is called once for each detail item (either in detail section or a section footer).

I just setup a test report mirroring what you are trying to do and I had no problems turning headers on and off with the type of formula I gave you.  I could turn on/ Report Headers, Page Headers, Group Headers, etc.  I would suggest you check your data for the actual values - maybe incorporate some case conversions to upper case before comparing, trimming trailing blanks, etc.

My report was structured in this way:

Page Header
Group Header
Details
  Sub Report Linked to A field In Details
    Report Header
    Page Header
    Group Header
    Details
Group Footer
Page Footer

and resulted in output like

Page Header
Group Header
Details
  Sub Report
Details
  Sub Report
Details
  Sub Report

etc.

0
 

Author Comment

by:jpresser
ID: 6224784
I solved the problem with the following:

strSQL = "SELECT * FROM PDTItemQ WHERE intPDTID = " & lngPDTID & " AND strLeadType = 'VDD' AND strDeviceType = 'Brady'"
 rstItemInfo.Open strSQL, conSFAClient.madoService, adOpenKeyset, adLockOptimistic
    If Not rstItemInfo.EOF And Not rstItemInfo.BOF Then
    frmRptViewer.Report38.Subreport5_UnboundBoolean1.SetUnbound   FieldSource ("TRUE")
    Else
      frmRptViewer.Report38.Subreport5_UnboundBoolean1.SetUnboundFieldSource ("FALSE")
End If

I placed an UnboundBoolean variable on the subreport and used the above to pass the results of the query to this variable then in the report I added the following:

if{@UnboundBoolean1} = TRUE Or {PDTItemQ.strDeviceType} = "Tachy" then
   False
else
   TRUE

The Tachy part is for another condition that had to be satisfied, but is superflous to the solution.

This works for all cases.

I now have another problem that I am trying to solve.  The problem is that when now tachy information is present and I have a VDD lead, I want to beable to move where the column is displayed.  Is it possible to be able to move a position through code?  

Thanks for your help.

Let me know if I have to open another question.  Even though you did not solve the first problem I will give you the points for your effort.
0
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 50 total points
ID: 6224971
Part 1 - You're welcome.  Glad you found a solution.  It had not been clear to me that you were trying to call the subreport from within VB.

Part 2 - If you are using the report designer components you can change any part of the report you want through code.  The FieldObject is the object I believe you want to modify.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

10 Experts available now in Live!

Get 1:1 Help Now