Results 1 to 3 of 3

Thread: Date Range Formula for Crystal Reports 10

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2021
    Posts
    18

    Date Range Formula for Crystal Reports 10

    I am trying to use a start date and end date input fields on a VB6 form to select the date range for a Crystal Reports 10 report. This use work in Crystal Report 5 with an Access 97 back end. I upgraded to Crystal Report 10 with an Access 2000 format. It now crashes the program (note all other reports that do not call a date range in the selection formula work perfect). I have tried a dozen examples I found online, but none of them seem to work. Any suggestions you could give would be greatly appreciated. Below is my initial code that I need to modify:

    Private Sub PrintRecord()

    Dim dtEndDate As String
    Dim dtStartDate As String
    Dim stMsg As String

    'Crystal Report Variables
    Dim strReportPath As String
    Dim strReportName As String


    'Set path to report file
    strReportPath = App.Path

    'Open the New report
    Set MyReport = New CRAXDRT.Report

    strReportName = "\DSLog.rpt"

    'Set date variables

    dtStartDate = Format(CVDate(txtStartDate.Text), "\D\a\t\e\(yyyy\,mm\,dd\)")
    dtEndDate = Format(CVDate(txtEndDate.Text), "\D\a\t\e\(yyyy\,mm\,dd\)")


    'Set selection formula to current record
    MyReport.SelectionFormula = "{DSFHead.DSDate} IN " & dtStartDate & " TO " & dtEndDate & ""

    'Set date paramenter values to print in report
    MyReport.ParameterFields(0) = "StartDate; " & dtStartDate & " ; True"
    MyReport.ParameterFields(1) = "EndDate; " & dtEndDate & " ; True"

    'Set selection formula to current record
    Set MyReport = Appl.OpenReport("" & strReportPath & "" & strReportName)

    'Open the form for viewing
    ReportView.Show vbModal

    'Reset the report definition
    Set MyReport = Nothing

    Exit Sub

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,900

    Re: Date Range Formula for Crystal Reports 10

    What line of code does it crash on and what error do you get?
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2021
    Posts
    18

    Re: Date Range Formula for Crystal Reports 10

    Quote Originally Posted by FunkyDexter View Post
    What line of code does it crash on and what error do you get?
    I have a separate form with a Crystal Report control that I pass report definations to named "ReportView". I was able to get the report to view with the correct date ranges using the code below:

    'Set selection formula to current record
    Set MyReport = Appl.OpenReport("" & strReportPath & "" & strReportName)

    MyReport.RecordSelectionFormula = "{DSFHead.DSDate} >= " & "Date (" & Format(FrmPrintDSLog.txtStartDate, "YYYY,mm,dd") & ")" & " AND {DSFHead.DSDate} <= " & "Date (" & Format(FrmPrintDSLog.txtEndDate, "YYYY,mm,dd") & ")"

    ReportView.Show vbModal

    The problem I am having now is passing the VB form input field (i.e. txtStartDate and txtEndDate) to parameter fields in the Crystal Reports report. These are used to display the date range in the report header.

    I have tried both:

    dtStartDate = Format(CVDate(txtStartDate.Text), "\D\a\t\e\(yyyy\,mm\,dd\)")
    dtEndDate = Format(CVDate(txtEndDate.Text), "\D\a\t\e\(yyyy\,mm\,dd\)")

    and

    dtStartDate = Format(FrmPrintDSLog.txtStartDate, "YYYY,mm,dd")
    dtEndDate = Format(FrmPrintDSLog.txtEndDate, "YYYY,mm,dd")

    When I run the following lines of code, I get a "Method 'ParameterFields' of object 'IReport' failed" message.

    'Set date paramenter values to print in report
    MyReport.ParameterFields(0) = "StartDate; " & dtStartDate & " ; True"
    MyReport.ParameterFields(1) = "EndDate; " & dtEndDate & " ; True"

    I was hoping I could get some help on how to pass an VB input text box value to a Crystal Report parameter field. Thanks!!!!!
    Last edited by MudManiac; May 24th, 2022 at 10:50 AM.

Tags for this Thread

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