Hi!
I'm creating an application where the user can select to export the crystal report without open it. The user will not see the report but it should run so I can have the data to export. I'm having problems when I try to close the report viewer form. I get the message: "InvalidOperationException was unhandled. Value Close() cannot be called while doing CreateHandle()". Does anyone know how should I close this report without errors?
Thanks!!!!
rptDoc1.ExportToDisk(ExportFormatType.ExcelRecord, filePath);
crRV1.ReportSource = rptDoc1;
if (MessageBox.Show("Report " + filePath + " exported successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
{
this.Hide();
this.Close(); // I get the message here: InvalidOperationException was unhandled. Value Close() cannot be called while doing CreateHandle().
this.Dispose();
}

Dipal ChoksiRank #199 · 12K reputationPosted May 12, 2008, 8:17 PM EDT
Hi,
Are you calling this code in the Load event handler? That could be the problem...
I am just trying to guess your issue from the information you have given and the error message..
Patricia Probst9 reputationPosted May 13, 2008, 4:38 AM EDT
Yes, I am... But I don't see another way to do it!
This form is only used to run the reports. It's called from another forms and runs crystal reports on it. When I need to only to export the reports, the form shouldn't be showed to the user but still have to run to get the data and export it to excel.
Do you have any sugestions?
Mahesh ChandRank #1 · 393.3K reputationPosted May 13, 2008, 6:06 AM EDT
Here is an article on how to export a Crystal Report to Excel, PDF and Doc formats programmatically:
http://www.c-sharpcorner.com/UploadFile/mahesh/ExportCRtoPDF10062006161918PM/ExportCRtoPDF.aspx