cancel
Showing results for 
Search instead for 
Did you mean: 

Error in formula <Record_Selection> This field name is not known.

Former Member
0 Kudos

I'm have a very frustrating time getting this report to work.

Version CR: 11.5 R2A SP6 (11.5.3700)

I am adding a new report to a well established application developed in VB 2005.

The application is using the CR SDK to accomplish most things.

My form (crptInsulationReportSummary) is connected to a SQL Server 2008 data source.

While in development mode I can select the "Main Report Preview" tab and see that the report is connected properly and that data shows up in the report.

When the application is run the following occurs in the order presented:

clsInsulationReportSummary.InitializeDataSet()

call PrintInsulationReportSummary()

     CrystalReportsHelper.DatabaseIntializationLion

     InsulationSummaryReport.RecordSelectionFormula = ...

     InsulationSummaryReport.SetDataSource( ...

The code for the above routines is pasted below.

It seems very simple and straightforward, however no matter what I try (I've even deleted the report and started from scratch) I keep getting the following error depicted in the image below.

I'm not getting an error, per se, just a blank report, but when I dig through the object this is what I find.

Let me know if you need any more information.

Thank you.

Tim Caldwell



(contents for above calls)

Public Class clsInsulationReportSummary

    Public Shared dsInsulationReportSummary As DataSet

    Public Shared Sub InitializeDataSet()

        dsInsulationReportSummary = New DataSet

        dsInsulationReportSummary.Tables.Add("vBOMInsulationReportSummary")

    End Sub

  End Class

    Private Sub PrintInsulationReportSummary()

        Dim InsulationSummaryReport As CrystalDecisions.CrystalReports.Engine.ReportDocument

        InsulationSummaryReport = New crptInsulationReportSummary

        Try

            CrystalReportsHelper.DatabaseIntializationLion(InsulationSummaryReport)

            InsulationSummaryReport.RecordSelectionFormula = " ({vBOMInsulationReportSummary.head_order_nbr} = 'SDJ120123-17')"

            InsulationSummaryReport.SetDataSource(clsInsulationReportSummary.dsInsulationReportSummary.Tables.Item("vBOMInsulationReportSummary"))

        Catch ex As Exception

            MessageBox.Show("Error Generating Report: StackTrace:" & ex.StackTrace())

        End Try

        Dim CrystalReportViewerForm As New frmCrystalReportViewer

(set break point here)          CrystalReportViewerForm.CrystalReportViewer1.ReportSource = InsulationSummaryReport

        ETIBomBlowerGlobalFunctions.LogReport(InsulationSummaryReport)

        CrystalReportViewerForm.Show() 'With Logging

        InsulationSummaryReport = Nothing

    End Sub

Public Class CrystalReportsHelper

    Shared Function DatabaseIntializationLion(ByRef Rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument) As Boolean

        Dim crtableLogoninfos As New TableLogOnInfos()

        Dim crtableLogoninfo As New TableLogOnInfo()

        Dim crConnectionInfo As New ConnectionInfo()

        Dim CrTables As Tables

        Dim CrTable As Table

        With crConnectionInfo

            .ServerName = "Lion"

            .DatabaseName = "QWright"

            .UserID = "xxxxxxxxxx" (x'd out for security)

            .Password = "xxxxxxxxxx" (x'd out for security)

        End With

        CrTables = Rpt.Database.Tables

        'Loop through each table in the report and apply the

        'LogonInfo information

        For Each CrTable In CrTables

            Select Case CrTable.Name

                Case "vENG_BomGen_LineDetail", _

                     "vENG_BomGen_Costing", _

                     "vENG_BomGen_Costing_Forecast", _

                     "vLineDetailInnerJoinBomGenCosting", _

                     "vLineDetail", _

                     "vCoilAttributes", _

                     "vBOMInsulationReportSummary"

                    crtableLogoninfo = CrTable.LogOnInfo

                    crtableLogoninfo.ConnectionInfo = crConnectionInfo

                    CrTable.ApplyLogOnInfo(crtableLogoninfo)

            End Select

        Next

        Return True

    End Function

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

The following is weird in your code:

1)

InsulationSummaryReport.RecordSelectionFormula = " ({vBOMInsulationReportSummary.head_order_nbr} = 'SDJ120123-17')"

2)

CrystalReportsHelper.DatabaseIntializationLion(InsulationSummaryReport) 

            InsulationSummaryReport.RecordSelectionFormula = " ({vBOMInsulationReportSummary.head_order_nbr} = 'SDJ120123-17')"

            InsulationSummaryReport.SetDataSource

3)

CrTable.ApplyLogOnInfo(crtableLogoninfo)

So, as the code runs, it looks like you set a record selection formula before any data is passed to the report. Then you pass in a dataset. Then you logon to a database, thus passing in data from a database.

Either use a dataset, or a database connection. Once you've decided which, set the selection formula. E.g.; the general flow would be:

Load report

Connect to database (via ApplyLogOnInfo or dataset, but not both)

Apply the selection formula

View / print / export the report

- Ludek

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Share Your Knowledge in SCN Topic Spaces

Former Member
0 Kudos

Ludek,

Just an FYI I basically copied another reports code and changed everything to point to my report.

So, even though it may not be kosher to do it this way, it works for other reports.

I'm just using what someone else has coded, because we don't normally do our reports like this.

I'm not saying it's right, I'm saying it works in other cases.

If I take out the dataset code and set the recordselectionformula after the database has been intialized (logged on) then I get everything in the view/table.

It appears to be ignoring my recordselectionformula.

However, I noticed that when I put a breakpoint on the this line:

     CrystalReportViewerForm.CrystalReportViewer1.ReportSource = InsulationSummaryReport

and then check the InsulationSummaryReport object with the watch window using shift+F9, I can see that the recordselectionformula is set properly and the rows.count is what I expect it to be.

I close the watch window and continue execution of the code and my report pops-up exactly as I expect it to look.

Very weird.

So, I then add a couple of debug.print statements and after messing around with them I have found that if I add this debug statement:

     Debug.Print(CStr(InsulationSummaryReport.Rows.Count))

It ensure the report is correct everytime.

If I take it out, I get all records from the view/table.

What the heck is up with that?

former_member183750
Active Contributor
Former Member
0 Kudos

Thanks Ludek, you're the best!

This is exactly what the problem turned out to be.

I would suggest putting in multiple entries for that KB though.

I was upgrading to CR XI R2A SP6, not CR 2008.

Again, thank you!

Timothy Caldwell

former_member183750
Active Contributor
0 Kudos

Hello Timothy

Many thanks. I actually feel quite guilty for not thinking of that issue in the 1st place. It's an old issue that comes up rarely - not sure why it comes up for some unlucky souls and not others. But I'm glad it's working now.

Happy coding,

- Ludek

Answers (0)