Results 1 to 22 of 22

Thread: crystal report formula

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    crystal report formula

    anyone know why I can't pass this parameter to my report?

    VB Code:
    1. oRpt = New CrystalReport1() ' create new instance of the report object
    2. oRpt.RecordSelectionFormula = "begindate ='" & Format(tranPeriod, "MM/dd/yyyy") & "'"
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  2. #2

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    I have another question...is there a way to add to the sql query in Crystal? When I right click the DataBase Field, I can get to Show Query, but can't edit it...
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Either pass the formula to the CrystalReportViewer or pass it to the report object. In case you want to pass it to the report object it should be:
    VB Code:
    1. oRpt.[b]DataDefinition[/b].RecordSelectionFormula = "begindate ='" & Format(tranPeriod, "MM/dd/yyyy") & "'"
    And if you want to pass it to the report viewer
    VB Code:
    1. crystalReportViewer1.SelectionFormula = ....
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    I'm getting an error:

    Error in formula <record_Selection>
    "begindate='05/05/2003"
    The remaining text does not appear to be part of the formula

    I created a formula in Crystal and named it begindate and placed it on my report.

    VB Code:
    1. Dim oRpt As CrystalReport1 ' create new report object
    2. oRpt = New CrystalReport1() ' create new instance of the report object
    3. oRpt.DataDefinition.RecordSelectionFormula = "begindate ='" & Format(tranPeriod, "MM/dd/yyyy") & "'"
    4. CrystalReportViewer1.ReportSource = oRpt

    I have this code in the page_load of the form...
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I think you have to use # around the date.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    the date time literal not understood

    VB Code:
    1. CrystalReportViewer1.SelectionFormula = "#begindate#"
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    you have to build your formula string in a way that when it's parsed it reads like
    begindate=#05/05/2003#
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    attached
    Attached Files Attached Files
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  9. #9
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    It seems your formula puts an extra ' before the #02/05/2003#
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  10. #10

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    Crystal puts in the single quote at the front and back..I took out my single quotes, but still get the same error msg...I'll deal with it tomaro...thanks for all the input Luna...

    VB Code:
    1. oRpt.DataDefinition.RecordSelectionFormula = "begindate =#" & Format(tranPeriod, "MM/dd/yyyy") & "#"
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  11. #11
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I think you need {} around the field names too in the formula text:
    VB Code:
    1. oRpt.DataDefinition.RecordSelectionFormula = "{begindate} =#" & Format(tranPeriod, "MM/dd/yyyy") & "#"

    Try it, if still getting problem i think the # and ' issue should be considered again. I am too lazy to check it
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  12. #12

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    hey lun, I don't think thats the issue. I replaced the date with a string and I still get the same error...

    VB Code:
    1. oRpt.DataDefinition.RecordSelectionFormula = "begindate='" & work_unit & "'"
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  13. #13
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    and putting the field name in {} still produced error?
    Try a working formula at design time and the copy paste the text to code.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  14. #14

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    yup
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  15. #15

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    I'm going to create a Dataset instead and pass my paramaters in the DS first then run my report
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  16. #16
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    ok, I think I found the final soultion:
    You have to mention the table name in the formula.
    so that will be:
    VB Code:
    1. oRpt.DataDefinition.RecordSelectionFormula = "{mytablename.begindate}='" & work_unit & "'"
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  17. #17

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    hey Lun, I decided to create a Dataset and use that to get the query I need for the report...I'm using the code below, and I'm not getting any errors, but the output on the report is the same as before, it's giving me all the data in the DB. I think it's using the query I created when I made my report...do you know how Ic an kill that query so it only uses the Dataset to fill the report?


    VB Code:
    1. Dim cmdView As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select purchase_date,credit_card_no,vendor_name,transaction_amt,sales_tax_amt,status_ind from pcms.pcms_pcard_transaction_header where purchase_date between TO_DATE('" & tranPeriod & "','mm/dd/yyyy') and TO_DATE('" & tranPeriodEnd & "','mm/dd/yyyy') ", objCon)
    2.         ds = New DataSet()
    3.         cmdView.Fill(ds, "cards")
    4.  
    5.         Dim oRpt As New CrystalReport1() ' create new report object
    6.         oRpt.SetDataSource(ds)
    7.         CrystalReportViewer1.ReportSource = oRpt
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  18. #18
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    1- Give the solution i gave you a try. It should work.
    2- If you decide to base your report on dataset instead of Database, you should add the dataset at desing time to your project. Then at desing time you should use the dataset file,lets say its mydataset.XSD, as the datasourse of your report and drag the fields from there to your report.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  19. #19

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    with your solution I wasn't getting the value from a table, it was coming from my app. I wanted to place the transaction period on the top of my report, so I was grabbing that value from a combobox on my form and then calling it by the formula name on the top of the report.
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  20. #20
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    ???

    In your selection formula you should provide both the table name and filed name. So if the table in your database is called mytable then you should use {mytablename.begindate}=yourdesiredvalue
    in your formula. It's quite clear.
    Last edited by Lunatic3; May 27th, 2003 at 12:48 PM.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  21. #21

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    this is how I was doing it in VB6...it worked fine.


    VB Code:
    1. CrystalReport1.Formulas(0) = "begindate ='" & Format(mdate, "mm/dd/yyyy") & "'"
    2.       CrystalReport1.Formulas(1) = "enddate = '" & Format(mdate2, "mm/dd/yyyy") & "'"
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  22. #22
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    VB Code:
    1. oRpt.DataDefinition.RecordSelectionFormula = "[b]{tablenamehere.[/b]begindate[b]}[/b] ='" & Format(tranPeriod, "MM/dd/yyyy") & "'"

    This works fine in you should take care of {} and tablename before the field name.

    help://MS.VSCC/MS.MSDNVS/crystlmn/html/crtskselectionformulasruntimecustomization.htm
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width