Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

RecordSelectionFormula disappears VB.NET 2010

$
0
0

I am getting myself more confused as I read about how to properly view a report in VB.NET Crystal Reports Viewer.  So it's now time I ask for some help.

First, I am using VB.NET 2010 with CR for VS 13.0.9.1312 installed and I have the runtime files installed as well.  I am having problems with several things but I will only put on issue in a thread for ease of tracking.

 

Scenario:  The viewer I am creating will use a MySQL database and/or csv files.  I have my program creating the DSN entries and have confirmed they work properly.  With some help of people here, I am able to switch the reports to the proper DSN as needed (you will see this in the code below).  All reports are external and may or may not have been created by me.  The program will allow users to run any report they wish to create.  Therefore, I will not know anything about the report including the DSN before it is run.  I cannot pass parameters from my program because I will not know ahead of time what parameters exist and what information to prompt for.  So I am letting the report itself trigger the prompts for the parameters.  Almost all of this is working fine when I have the report set to preview mode on screen.

 

The issue:  It is ignoring the record selection formula in each report so that it brings back all records, unless I specifically tell the viewer what the record selection formula is while running the report.  I am using the ReportDocument and thought that the ReportDocument.RecordSelectionFormula in it would carry through, but when I put the RecordSelectionFormula on the report itself, it is blank until I assign it to the viewer control.  Parameters used outside the RecordSelectionFormula are prompted and used properly in my testing so far, but not the one's inside.

 

So my two questions are:

1) Is there anything that I should consider changing to make the code below work better in general?  Maybe the order of the commands is causing a problem?

2) Why would I have to assign the line below (test = a string containing the original recordselectionformula of the report from just after loading.  I'll rename it later if I have to keep it)?

 

         crViewer.SelectionFormula = test

 

 

Public Sub DBLogin(ByVal strCRReport As String, _
                      ByVal strServerName As String, _
                      ByVal strDatabaseName As String, _
                      ByVal strUserid As String, _
                      ByVal strPassword As String)
      'sets up login for database
      'check each report for current

      Dim strcsvDatabaseName As String = FindFormsDSNPath()

      Dim strcsvServerName As String = cstrProgramTitle & " CSV Forms"


      crReport.Close()

 

      Try

         crReport.Load(strCRReport)
         crReport.ReportOptions.EnableSaveDataWithReport = False

         Dim x As Integer = crReport.Subreports.Count

         x = crReport.DataDefinition.ParameterFields.Count
        

         Dim strReportDSN As String '= GetReportDSN

         sslblFilename.Text = strFileName & " - CR " & crReport.ReportClientDocument.MajorVersion & "." & crReport.ReportClientDocument.MinorVersion


         Dim crTableLogonInfo As TableLogOnInfo

         'Set the database properties and security credentials
         Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
         crConnectionInfo.ServerName = strServerName
         crConnectionInfo.DatabaseName = strDatabaseName
         crConnectionInfo.UserID = strUserid
         crConnectionInfo.Password = strPassword


         Dim csvConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
         csvConnectionInfo.ServerName = strcsvServerName
         csvConnectionInfo.DatabaseName = strcsvDatabaseName
         csvConnectionInfo.UserID = ""
         csvConnectionInfo.Password = ""


         'Apply the ConnectionInfo to the report tables
         Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
         Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

         crTables = crReport.Database.Tables

         crTable = crTables(0)
         strReportDSN = crTable.LogOnInfo.ConnectionInfo.ServerName
         strReportDSN = GetReportDSN(strReportDSN)


         Dim blntemp As Boolean
         For Each crTable In crTables
            blntemp = False
            crTableLogonInfo = crTable.LogOnInfo
            If strReportDSN = strServerName Then
               crTableLogonInfo.ConnectionInfo = crConnectionInfo
            Else
               crTableLogonInfo.ConnectionInfo = csvConnectionInfo
            End If
            crTable.ApplyLogOnInfo(crTableLogonInfo)

            blntemp = crTable.TestConnectivity()
         Next


         Dim mySubReport As CrystalDecisions.CrystalReports.Engine.ReportDocument

         Dim mySubReports As CrystalDecisions.CrystalReports.Engine.Subreports


         mysubreports = crReport.Subreports
         For Each mySubReport In mySubReports


            Dim crsubTables As CrystalDecisions.CrystalReports.Engine.Tables
            Dim crsubTable As CrystalDecisions.CrystalReports.Engine.Table

            mySubReport = crReport.OpenSubreport(mySubReport.Name)

            'find current DSN
            crsubTables = mySubReport.Database.Tables
            crsubTable = crsubTables(0)
            strReportDSN = crsubTable.LogOnInfo.ConnectionInfo.ServerName
            strReportDSN = GetReportDSN(strReportDSN)


            For Each crsubTable In crsubTables
               blntemp = False
              
               crTableLogonInfo = crsubTable.LogOnInfo

               'Reset DSN to program connection for database or csv files
               If strReportDSN = strServerName Then
                  crTableLogonInfo.ConnectionInfo = crConnectionInfo
               Else
                  crTableLogonInfo.ConnectionInfo = csvConnectionInfo
               End If
               crsubTable.ApplyLogOnInfo(crTableLogonInfo)

               blntemp = crsubTable.TestConnectivity()
            Next
         Next

         'Find the RecordSelectionFormula and test if it carries through

         Dim test As String = crReport.RecordSelectionFormula


         'check if to be sent direct to printer and send all pages
         If Not autoforms Is Nothing AndAlso autoforms.ToPrinter Then
            crReport.PrintOptions.PrinterName = autoforms.Printer
            crReport.PrintToPrinter(1, True, 0, 0)

         End If


         'check if to be sent direct to pdf and send all pages
         If Not autoforms Is Nothing AndAlso autoforms.ToPDF Then

            Dim strPDFFilename As String = autoforms.PDFPath & "\" & autoforms.ReportName & " " & autoforms.ReportType & ".pdf"
            strPDFFilename = Replace(strPDFFilename, " ", "_")
           
            SendExport(strPDFFilename, "PDF")

         End If


         'if not preview then close form
         If Not autoforms Is Nothing AndAlso Not autoforms.Preview Then
            Me.Close()
         End If
        
         'setup viewer options
         crViewer.ReportSource = Nothing
         crViewer.ReportSource = crReport

         Dim intExportFormatFlags As Integer
         intExportFormatFlags = ViewerExportFormats.PdfFormat Or
                                 ViewerExportFormats.ExcelFormat Or
                                 ViewerExportFormats.ExcelRecordFormat Or
                                 ViewerExportFormats.XLSXFormat Or
                                 ViewerExportFormats.CsvFormat

         crViewer.AllowedExportFormats = intExportFormatFlags
         crViewer.ShowLogo = False

'Note first line here does not work, but second one does
         'crReport.RecordSelectionFormula = test
         crViewer.SelectionFormula = test

         crViewer.Refresh()
         crViewer.Show()

      Catch ex As Exception
         MessageBox.Show(ex.Message & vbCrLf & ex.ToString)

      End Try

     

   End Sub

 

 

All help is appreciated.  TIA, rasinc


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>