Question : Using Report Designer Component with Visual C++ 6.0

Hi..

[Using: Visual C++ 6.0, MFC Dialog-Based Application, Report Designer Component, Crystal Reports 8.5]

I'm trying to develop a dialog based application that opens a report and passes the required parameters then refresh and export it to a destination folder. The application uses Report Designer Component to pass parameters to a report programatically. I referred to document "scr_rdc_cpp.pdf" from Crystal Reports Support, and came up with the following code:

// CTestApp :
IApplicationPtr gApplication;
IReportPtr gReport;

// CTestDlg :
extern CReportSchedulerApp theApp;

void CTestDlg::OnOpenReport()
{
   CFileDialog fd(TRUE, "*.rpt", NULL, OFN_EXPLORER, "Crystal Reports|*.rpt||");

   if(fd.DoModal() == IDOK)
   {
      _bstr_t bsFile = fd.GetPathName();

      theApp.gApplication.CreateInstance("CrystalDesignRuntime.Application");
      theApp.gReport = theApp.gApplication->OpenReport(bsFile);
   }
}

void CTestDlg::OnRefreshReport()
{
   UpdateData(TRUE);

   VARIANT varFrom, varTo; // the report requires two date parameters: from & to
   DATE dFrom, dTo;
   SYSTEMTIME systFrom, systTo;

   m_tFromDate.GetAsSystemTime(systFrom); // a date-time picker control
   m_tToDate.GetAsSystemTime(systTo); // a date-time picker control

   VariantInit(&varFrom);
   VariantInit(&varTo);

   SystemTimeToVariantTime(&systFrom, &dFrom);
   SystemTimeToVariantTime(&systTo, &dTo);

   varFrom.vt   = VT_DATE;
   varFrom.date = dFrom;

   varTo.vt   = VT_DATE;
   varTo.date = dTo;

   theApp.gReport->GetParameterFields()->GetItem(1)->AddCurrentValue(varFrom);
   theApp.gReport->GetParameterFields()->GetItem(2)->AddCurrentValue(varTo);
}

When I run the application, and reach the call to AddCurrentValue(), I get "Abnormal Program Termination".. I think the part that causes this problem is the last two lines in the code shown above. The very strange thing that drives me crazy is that if I replace the call to AddCurrentValue() with GetCurrentValue(), the application works fine !!! I got the impression that I can read data, put I can't change.. i.e. gReport is readonly??

I realy need to solve this problem because the thing is this application is actually a report scheduler that will be used to schedule Crystal Reports to refresh and export automatically..

PLEASE HELP...

Answer : Using Report Designer Component with Visual C++ 6.0

Guys,

I figured out what was the source of the problem..

I was passing the date as {28-Nov-03 3:00:00 AM VT_DATE} but my report accepts only this: {28-Nov-03 12:00:00 AM VT_DATE} where the time is 12:00:00 AM, no more, no less (I don't know why)

Thanks for your replies.
Random Solutions  
 
programming4us programming4us