Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RecordSelectionFormula not being applied when PDF created

Status
Not open for further replies.

sayonion

Programmer
Oct 21, 2003
2
0
0
US
I'm using Crystal 9 and VB.Net in an .aspx page. The page has a CrystalReportViewer, and everytime the page loads, it loads the report, logs on, assigns the most recent RecordSelectionFormula, and then does DataBind.

The webpage also has a user control that creates and stores the most recent RecordSelectionFormula. The user control stores a reference to the CrystalReportViewer and the CrystalReportDocument. When the user clicks the user control's submit button, the user control reassembles the RecordSelectionFormula, applies it to the CrystalReportViewer and CrystalReportDocument, and does DataBind again.

The RecordSelectionFormula is applied and displayed correctly in the CrystalReportViewer; however, when the user clicks on the CrystalReportViewer's print button, selects the pages to print, and then clicks Print again, the pdf version of the report that Crystal makes displays all the data, and doesn't have the RecordSelectionFormula applied.

Thanks for your help!

frmCrystalReportViewer.aspx.vb
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' Remember which report to load later
txtReportName.Text = Request.QueryString("ReportName")
End If

' Initialize Crystal Report Viewer
Dim ReportDisplayName As String
Try
ReportDisplayName = InitReport()
PageTitle.InnerText = ReportDisplayName
Catch ex As Exception
lblTest.Text = ex.Message
End Try

' Set up search query stuff
SearchQuery1.SearchQueryTitle = ReportDisplayName
SearchQuery1.SubmitButtonText = "Get My Report"
SearchQuery1.SetCrystalReportViewerToBind(CrystalReportViewer1)
SearchQuery1.SetCrystalReportDocumentToBind(crReportDocument)
End Sub

Private Function InitReport() As String
Dim sPhysicalPath As String = HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH")
Dim ReportDisplayName As String

Dim crTableLogOnInfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim crTableCurrent As CrystalDecisions.Shared.TableLogOnInfo

Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
crReportDocument.Load(sPhysicalPath & "\Reports\rptArbitrationReport.rpt", OpenReportMethod.OpenReportByDefault)

For Each crTable In crReportDocument.Database.Tables
crTableCurrent = crTable.LogOnInfo
With crTableCurrent.ConnectionInfo
.ServerName = "server"
.DatabaseName = "database"
.UserID = "dbuser"
.Password = "pword"
End With
crTable.ApplyLogOnInfo(crTableCurrent)
Next crTable

crReportDocument.RecordSelectionFormula = ""
crReportDocument.RecordSelectionFormula = SearchQuery1.CrystalReportViewerSearchCriteria

CrystalReportViewer1.ReportSource = crReportDocument

CrystalReportViewer1.SelectionFormula = SearchQuery1.CrystalReportViewerSearchCriteria
CrystalReportViewer1.DataBind()

ReportDisplayName = "Arbitration"

Return ReportDisplayName & " Report"
End Function

User Control - SearchQuery.ascx.vb
This is called from SearchQuery's btnSubmit_OnClick
Public Sub DoSearch()
' Set the selection formula for a Crystal Reports Viewer
' Assumes that the report viewer has already had its logon info set
If Not IsNothing(ReportViewerToBind) Then
RptDocToBind.RecordSelectionFormula = GetCrystalReportViewerSearchCriteria()

ReportViewerToBind.SelectionFormula = GetCrystalReportViewerSearchCriteria()
ReportViewerToBind.DataBind()
ReportViewerToBind.Visible = True
End If
End Sub
 
You are in the wrong forum. This forum is for Crystal Enterprise, you should be posting this to one of the other CD forums related to Crystal Reports!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top