Hi:
Trying to get subreport running here. Reports w/o subs run fine if I comment out all the subreport stuff in second code block below. W/o commenting out subreport stuff, not even the basic data from the dataset is displayed, only the variables I set in code. Problems totally associated with adding subreport. No errors reported.
Calling Code bloc:
//----------------------------------------------------------------------------
void __fastcall TReportDM:rintStdFormLetter(int Top, int Left,
int Height, int Width, int Kind, int Id)
{
// TStringList *LetterBody = new TStringList();;
// LetterBody->Clear();
String FileName;
String Distribution = "1";
switch (Kind)
{
case 1 : FileName = "WelcomeLetterMem";break;
case 2 : FileName = "WelcomeLetterAssoc"; break;
case 4 : FileName = "WelcomeLetterConv"; break;
case 5 : FileName = "NonMemberInvitation"; break; //Single Id
case 6 : {FileName = "NonMemberInvitation";
Distribution = "2";
break;} //Bulk mailing
case 10 : FileName = "AdvertiserInvitation"; break;
case 11 : FileName = "AdvertiserRenewal"; break;
case 12 : FileName = "AdvertiserCancel"; break;
case 14 : FileName = "CancelMemberLetter"; break;
case 16 : FileName = "CancelCreditLetter"; break;
case 18 : FileName = "ReminderLetter"; break;
}
// RecoverFormLetterFile(FileName);
// String FilePath = SuP.CommonPath + "\\letters\\" + FileName + ".txt"; //".rtf";
// LetterBody->LoadFromFile(FilePath);
//Create the report background
CreateReportBackground(50,/*Top*/800, /*Left*/ Height, Width, "Printing Standard Form Letters");
//Set up report name
String ReportName;
String SubReportName;
if (Kind == 10 || Kind == 11 | Kind == 12)
{
ReportName = "StdAdvLetter";
}
else
{
ReportName = "StdLetter";
}
SubReportName = "StdLetterText";
CrpeADO->ReportName = "";
String ReportsPath = SuP.ReportsPath;
CrpeADO->ReportName = ReportsPath + "\\" + ReportName + ".rpt";
// CrpeADO->Subreports->Name = ReportsPath + "\\" + SubReportName + ".rpt";
String FullSubReportName = ReportsPath + "\\" + SubReportName + ".rpt";
//Recover the report from the database
if (!RecoverReportFile(true, ReportName, ReportsPath))
return;
if (!RecoverReportFile(true, SubReportName, ReportsPath))
return;
//Set up record selection
if (Kind != 5)
{
Id = 0;
}
String Description;
if (Kind == 1){Description = "Membership Welcome";}
else if (Kind == 2){Description ="Associate Welcome";}
else if (Kind == 4){Description = "Membership Welcome";}
else if (Kind == 5){Description = "Membership Invitation";}
else if (Kind == 6){Description = "Membership Invitation";}
else if (Kind == 16){Description = "Credit Cancellation";}
else if (Kind == 18){Description = "Membership Renewal";}
else if (Kind == 14){Description = "Membership Cancellation";}
//Retrieve the formulas
CrpeADO->Formulas->Retrieve();
//DSet record selection formula
CrpeADO->Formulas->Name = "Id";
CrpeADO->Formulas->Formula->Text = IntToStr(Id);
//Set Report description header and Text File ID and distribution (bulk vs individual
CrpeADO->Formulas->Name = "TextFileId";
CrpeADO->Formulas->Formula->Text = "\"" + Description + "\"";
CrpeADO->Formulas->Name = "Description";
CrpeADO->Formulas->Formula->Text = "\"" + Description + "\"";
CrpeADO->Formulas->Name = "Distribution";
CrpeADO->Formulas->Formula->Text = "\"" + Distribution + "\"";
//Set Organization Data arameters
CrpeADO->Formulas->Name = "OrgAcronym";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Acronym"] + "\"";
CrpeADO->Formulas->Name = "OrgName1";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Name1"] + "\"";
CrpeADO->Formulas->Name = "OrgName2";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Name2"] + "\"";
CrpeADO->Formulas->Name = "OrgAddress";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Address"] + "\"";
CrpeADO->Formulas->Name = "OrgCityStateZip";
String CityStateZip = SuP.suUserData->Values["City"] + ", " +
SuP.suUserData->Values["State"] + " " +
SuP.suUserData->Values["Zip"];
CrpeADO->Formulas->Formula->Text = "\"" + CityStateZip + "\"";
CrpeADO->Formulas->Name = "OrgPhone";
String Phone = Trim(SuP.suUserData->Values["Phone"]);
if (Phone != "")
Phone = "Phone: " + Phone;
CrpeADO->Formulas->Formula->Text = "\"" + Phone + "\"";
CrpeADO->Formulas->Name = "OrgFax";
String Fax = Trim(SuP.suUserData->Values["Fax"]);
if (Fax != "")
Fax = "FAX: " + Fax;
CrpeADO->Formulas->Formula->Text = "\"" + Fax + "\"";
CrpeADO->Formulas->Name = "OffHours1";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours1"] + "\"";
CrpeADO->Formulas->Name = "OffHours2";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours2"] + "\"";
CrpeADO->Formulas->Name = "OffHours3";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours3"] + "\"";
CrpeADO->Formulas->Name = "OffHours4";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours4"] + "\"";
CrpeADO->Formulas->Name = "OffHours5";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours5"] + "\"";
CrpeADO->Formulas->Name = "OrgMessage";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Mesg"] + "\"";
//Set print options
CrpeADO->PrintOptions->Retrieve();
CrpeADO->PrintOptions->Copies = 1;
CrpeADO->WindowParent = PrintForm;
//Run the print job
RunADOReport(CrpeADO->ReportName, FullSubReportName, true, 0, "NI");
while (!PrintWindowClosed)
Application->ProcessMessages();
}
And to call to the ADO:
//---------------------------------------------------------------------------
void __fastcall TReportDM::RunADOReport(String sReportName, String sSubReportName, bool LoadSQL, int Control, String InvDate)
{
bool HaveSubReport = false;
if (LoadSQL)
{
if (Trim(sSubReportName) != "")
{HaveSubReport = true;}
String sReportSQL = sReportName;
sReportSQL.Delete(sReportSQL.Pos(".rpt"), 5);
sReportSQL = sReportSQL + ".sql";
qrADOReports->SQL->Clear();
qrADOReports->SQL->LoadFromFile(sReportSQL);
if (HaveSubReport)
{
String sSubReportSQL = sSubReportName;
sSubReportSQL.Delete(sSubReportSQL.Pos(".rpt"), 5);
sSubReportSQL = sSubReportSQL + ".sql";
qrADOSubReports->SQL->Clear();
qrADOSubReports->SQL->LoadFromFile(sSubReportSQL);
}
if ((Trim(InvDate) != "NI") && (Control >= itDues) && (Control <= itCredit))
{
InvDate = "\'" + InvDate + "\'";
if (Control == itDues)
qrADOReports->SQL->Add(Format("WHERE MEMPAY2.REMIND_LET = %s", ARRAYOFCONST(((String)InvDate))));
else if (Control == itCredit)
qrADOReports->SQL->Add(Format("WHERE MEMPAY2.CRDREM_LET = %s", ARRAYOFCONST(((String)InvDate))));
}
}
PrintWindowClosed = false;
Screen->Cursor = crHourGlass;
TSCRObject *adoRecordSet = new TSCRObject();
TSCRObject *adoSubRecordSet;
if (HaveSubReport)
adoSubRecordSet = new TSCRObject();
ICRDataSource *tInterface;
ICRDataSource *tSubInterface;
String eMessage;
trADOReports->StartTransaction();
if (HaveSubReport)
qrADOSubReports->Open();
qrADOReports->Open();
if (CrpeADO->HasSavedData)
CrpeADO->DiscardSavedData = true;
try
{
adoRecordSet->SetDataSet(qrADOReports);
tInterface = *adoRecordSet;
if (HaveSubReport)
{
adoSubRecordSet->SetDataSet(qrADOSubReports);
tSubInterface = *adoSubRecordSet;
}
CrpeADO->Subreports->Retrieve();
CrpeADO->Subreports[0]; //pointing to main report
CrpeADO->Tables->Retrieve();
CrpeADO->Tables[0].DataPointer = &tInterface;
if (HaveSubReport)
{
CrpeADO->Subreports[1]; //pointing to subreport
CrpeADO->Tables->Retrieve();
CrpeADO->Tables[0].DataPointer = &tSubInterface;
}
CrpeADO->Subreports[0]; //point to Main Report before Executing
/* CrpeADO->Tables->Retrieve();
CrpeADO->Tables[0].DataPointer = &tInterface;*/
CrpeADO->Execute();
}
catch(...)
{
Screen->Cursor = crDefault;
adoRecordSet->FreeInstance();
if (HaveSubReport)
adoSubRecordSet->FreeInstance();
if (CrpeADO->LastErrorString != "")
{
eMessage = ("There was an error running the report. The "
"report code was " + IntToStr(CrpeADO->LastErrorNumber));
eMessage = eMessage + " and the message was " + CrpeADO->LastErrorString;
ShowMessage(eMessage);
if (PrintForm != NULL)
{
delete PrintForm;
PrintForm = NULL;
}
return;
}
else
throw;
}
Screen->Cursor = crDefault;
while (!PrintWindowClosed)
Application->ProcessMessages();
adoRecordSet->FreeInstance();
if (HaveSubReport)
adoSubRecordSet->FreeInstance();
trADOReports->Commit();
if (PrintForm != NULL)
{
delete PrintForm;
PrintForm = NULL;
}
}
Trying to get subreport running here. Reports w/o subs run fine if I comment out all the subreport stuff in second code block below. W/o commenting out subreport stuff, not even the basic data from the dataset is displayed, only the variables I set in code. Problems totally associated with adding subreport. No errors reported.
Calling Code bloc:
//----------------------------------------------------------------------------
void __fastcall TReportDM:rintStdFormLetter(int Top, int Left,
int Height, int Width, int Kind, int Id)
{
// TStringList *LetterBody = new TStringList();;
// LetterBody->Clear();
String FileName;
String Distribution = "1";
switch (Kind)
{
case 1 : FileName = "WelcomeLetterMem";break;
case 2 : FileName = "WelcomeLetterAssoc"; break;
case 4 : FileName = "WelcomeLetterConv"; break;
case 5 : FileName = "NonMemberInvitation"; break; //Single Id
case 6 : {FileName = "NonMemberInvitation";
Distribution = "2";
break;} //Bulk mailing
case 10 : FileName = "AdvertiserInvitation"; break;
case 11 : FileName = "AdvertiserRenewal"; break;
case 12 : FileName = "AdvertiserCancel"; break;
case 14 : FileName = "CancelMemberLetter"; break;
case 16 : FileName = "CancelCreditLetter"; break;
case 18 : FileName = "ReminderLetter"; break;
}
// RecoverFormLetterFile(FileName);
// String FilePath = SuP.CommonPath + "\\letters\\" + FileName + ".txt"; //".rtf";
// LetterBody->LoadFromFile(FilePath);
//Create the report background
CreateReportBackground(50,/*Top*/800, /*Left*/ Height, Width, "Printing Standard Form Letters");
//Set up report name
String ReportName;
String SubReportName;
if (Kind == 10 || Kind == 11 | Kind == 12)
{
ReportName = "StdAdvLetter";
}
else
{
ReportName = "StdLetter";
}
SubReportName = "StdLetterText";
CrpeADO->ReportName = "";
String ReportsPath = SuP.ReportsPath;
CrpeADO->ReportName = ReportsPath + "\\" + ReportName + ".rpt";
// CrpeADO->Subreports->Name = ReportsPath + "\\" + SubReportName + ".rpt";
String FullSubReportName = ReportsPath + "\\" + SubReportName + ".rpt";
//Recover the report from the database
if (!RecoverReportFile(true, ReportName, ReportsPath))
return;
if (!RecoverReportFile(true, SubReportName, ReportsPath))
return;
//Set up record selection
if (Kind != 5)
{
Id = 0;
}
String Description;
if (Kind == 1){Description = "Membership Welcome";}
else if (Kind == 2){Description ="Associate Welcome";}
else if (Kind == 4){Description = "Membership Welcome";}
else if (Kind == 5){Description = "Membership Invitation";}
else if (Kind == 6){Description = "Membership Invitation";}
else if (Kind == 16){Description = "Credit Cancellation";}
else if (Kind == 18){Description = "Membership Renewal";}
else if (Kind == 14){Description = "Membership Cancellation";}
//Retrieve the formulas
CrpeADO->Formulas->Retrieve();
//DSet record selection formula
CrpeADO->Formulas->Name = "Id";
CrpeADO->Formulas->Formula->Text = IntToStr(Id);
//Set Report description header and Text File ID and distribution (bulk vs individual
CrpeADO->Formulas->Name = "TextFileId";
CrpeADO->Formulas->Formula->Text = "\"" + Description + "\"";
CrpeADO->Formulas->Name = "Description";
CrpeADO->Formulas->Formula->Text = "\"" + Description + "\"";
CrpeADO->Formulas->Name = "Distribution";
CrpeADO->Formulas->Formula->Text = "\"" + Distribution + "\"";
//Set Organization Data arameters
CrpeADO->Formulas->Name = "OrgAcronym";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Acronym"] + "\"";
CrpeADO->Formulas->Name = "OrgName1";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Name1"] + "\"";
CrpeADO->Formulas->Name = "OrgName2";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Name2"] + "\"";
CrpeADO->Formulas->Name = "OrgAddress";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Address"] + "\"";
CrpeADO->Formulas->Name = "OrgCityStateZip";
String CityStateZip = SuP.suUserData->Values["City"] + ", " +
SuP.suUserData->Values["State"] + " " +
SuP.suUserData->Values["Zip"];
CrpeADO->Formulas->Formula->Text = "\"" + CityStateZip + "\"";
CrpeADO->Formulas->Name = "OrgPhone";
String Phone = Trim(SuP.suUserData->Values["Phone"]);
if (Phone != "")
Phone = "Phone: " + Phone;
CrpeADO->Formulas->Formula->Text = "\"" + Phone + "\"";
CrpeADO->Formulas->Name = "OrgFax";
String Fax = Trim(SuP.suUserData->Values["Fax"]);
if (Fax != "")
Fax = "FAX: " + Fax;
CrpeADO->Formulas->Formula->Text = "\"" + Fax + "\"";
CrpeADO->Formulas->Name = "OffHours1";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours1"] + "\"";
CrpeADO->Formulas->Name = "OffHours2";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours2"] + "\"";
CrpeADO->Formulas->Name = "OffHours3";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours3"] + "\"";
CrpeADO->Formulas->Name = "OffHours4";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours4"] + "\"";
CrpeADO->Formulas->Name = "OffHours5";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Hours5"] + "\"";
CrpeADO->Formulas->Name = "OrgMessage";
CrpeADO->Formulas->Formula->Text = "\"" + SuP.suUserData->Values["Mesg"] + "\"";
//Set print options
CrpeADO->PrintOptions->Retrieve();
CrpeADO->PrintOptions->Copies = 1;
CrpeADO->WindowParent = PrintForm;
//Run the print job
RunADOReport(CrpeADO->ReportName, FullSubReportName, true, 0, "NI");
while (!PrintWindowClosed)
Application->ProcessMessages();
}
And to call to the ADO:
//---------------------------------------------------------------------------
void __fastcall TReportDM::RunADOReport(String sReportName, String sSubReportName, bool LoadSQL, int Control, String InvDate)
{
bool HaveSubReport = false;
if (LoadSQL)
{
if (Trim(sSubReportName) != "")
{HaveSubReport = true;}
String sReportSQL = sReportName;
sReportSQL.Delete(sReportSQL.Pos(".rpt"), 5);
sReportSQL = sReportSQL + ".sql";
qrADOReports->SQL->Clear();
qrADOReports->SQL->LoadFromFile(sReportSQL);
if (HaveSubReport)
{
String sSubReportSQL = sSubReportName;
sSubReportSQL.Delete(sSubReportSQL.Pos(".rpt"), 5);
sSubReportSQL = sSubReportSQL + ".sql";
qrADOSubReports->SQL->Clear();
qrADOSubReports->SQL->LoadFromFile(sSubReportSQL);
}
if ((Trim(InvDate) != "NI") && (Control >= itDues) && (Control <= itCredit))
{
InvDate = "\'" + InvDate + "\'";
if (Control == itDues)
qrADOReports->SQL->Add(Format("WHERE MEMPAY2.REMIND_LET = %s", ARRAYOFCONST(((String)InvDate))));
else if (Control == itCredit)
qrADOReports->SQL->Add(Format("WHERE MEMPAY2.CRDREM_LET = %s", ARRAYOFCONST(((String)InvDate))));
}
}
PrintWindowClosed = false;
Screen->Cursor = crHourGlass;
TSCRObject *adoRecordSet = new TSCRObject();
TSCRObject *adoSubRecordSet;
if (HaveSubReport)
adoSubRecordSet = new TSCRObject();
ICRDataSource *tInterface;
ICRDataSource *tSubInterface;
String eMessage;
trADOReports->StartTransaction();
if (HaveSubReport)
qrADOSubReports->Open();
qrADOReports->Open();
if (CrpeADO->HasSavedData)
CrpeADO->DiscardSavedData = true;
try
{
adoRecordSet->SetDataSet(qrADOReports);
tInterface = *adoRecordSet;
if (HaveSubReport)
{
adoSubRecordSet->SetDataSet(qrADOSubReports);
tSubInterface = *adoSubRecordSet;
}
CrpeADO->Subreports->Retrieve();
CrpeADO->Subreports[0]; //pointing to main report
CrpeADO->Tables->Retrieve();
CrpeADO->Tables[0].DataPointer = &tInterface;
if (HaveSubReport)
{
CrpeADO->Subreports[1]; //pointing to subreport
CrpeADO->Tables->Retrieve();
CrpeADO->Tables[0].DataPointer = &tSubInterface;
}
CrpeADO->Subreports[0]; //point to Main Report before Executing
/* CrpeADO->Tables->Retrieve();
CrpeADO->Tables[0].DataPointer = &tInterface;*/
CrpeADO->Execute();
}
catch(...)
{
Screen->Cursor = crDefault;
adoRecordSet->FreeInstance();
if (HaveSubReport)
adoSubRecordSet->FreeInstance();
if (CrpeADO->LastErrorString != "")
{
eMessage = ("There was an error running the report. The "
"report code was " + IntToStr(CrpeADO->LastErrorNumber));
eMessage = eMessage + " and the message was " + CrpeADO->LastErrorString;
ShowMessage(eMessage);
if (PrintForm != NULL)
{
delete PrintForm;
PrintForm = NULL;
}
return;
}
else
throw;
}
Screen->Cursor = crDefault;
while (!PrintWindowClosed)
Application->ProcessMessages();
adoRecordSet->FreeInstance();
if (HaveSubReport)
adoSubRecordSet->FreeInstance();
trADOReports->Commit();
if (PrintForm != NULL)
{
delete PrintForm;
PrintForm = NULL;
}
}