• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1824
  • Last Modified:

Passing a boolean flag to crystal reports

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
jpresser
Asked:
jpresser
  • 8
  • 7
1 Solution
 
DRRYAN3Commented:
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
 
DRRYAN3Commented:
JPresser

Please clear up the outstanding open questions showing in your profile.
0
 
jpresserAuthor Commented:
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
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
DRRYAN3Commented:
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
 
jpresserAuthor Commented:
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
 
DRRYAN3Commented:
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
 
jpresserAuthor Commented:
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
 
DRRYAN3Commented:
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
 
jpresserAuthor Commented:
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
 
jpresserAuthor Commented:
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
 
DRRYAN3Commented:
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
 
jpresserAuthor Commented:
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
 
DRRYAN3Commented:
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
 
jpresserAuthor Commented:
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
 
DRRYAN3Commented:
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

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now