Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subreports and data sources

Status
Not open for further replies.

CMR

Programmer
Apr 30, 2002
76
0
0
AU
Hi all.

I have a report which I designed in Crystal 8 while connecting to database A. I have an application which tries to run the report on Database B.
The problem is, when I run the application against database B and try the report, it is still connecting to Database A, even though I've removed all references to the database from the report locations (the locations are "table" rather than "database.owner.table").
It's a C++ application and I'm using the Crystal API to access the Crystal functionality (i.e. I've included the PEPLUS.CCP & .H files in my project etc.) and I'm "logging in" using the CRPEngine::LogonServer() function to connect my report to the database.

All this seems to work fine but the results are still coming from the wrong database...

Obviously, I need to remove database references from my report but I don't know where.

Any help would be greatly appreciated.

CMR
 
More information:
It seems that not all the data is being retrieved from the wrong database - just that in the subreports (there are several subreports in this report - they constitute the bulk of the data).
This would mean that LogOnServer() is working correctly - I'm also using CRPEJob::SetNthTableLogonInfo() when I've opened the report job, which is working fine.
It's just the subreports... so the question is, how can I set the logon info for my subreports; indeed, how can I get the subreports from the report to set the info on....

Thanks in advance

CMR
 
Here's a piece of code in VB that retrieves a subreport:


Code:
With oRpt
    'get the subreport reference
    For Each oSec In .Sections
        For Each oRptObj In oSec.ReportObjects
            If oRptObj.Kind = crSubreportObject Then
                Set oSubRptObj = oRptObj
                
                Set oSubRpt = oSubRptObj.OpenSubreport
                
                'make sure the subrpt is pointing to the right directory
                oSubRpt.Database.Tables(1).SetLogOnInfo sRptDir & _
                			oSubRpt.Database.Tables(1).Location
            End If
        Next oRptObj
    Next oSec
End With
 
Hi CRM,

I'm pasting the same answer I had for almost the same question from Michelle for "PAssing datasource to Subreports". Let me know if this helps.

For a subreport. you have to get all the subreports from your report object, loop through each subreport open it and set the location for the subreport.

Following is the code.
HRESULT CMyClass::processSubReports(_variant_t varDataSource, CRYSTALCRAXDRT::IReportPtr& spReport,_bstr_t bstrServer, _bstr_t bstrDatabase, _bstr_t bstrUserID, _bstr_t bstrPassword)
{
HRESULT hr = S_OK;

// Find out if there are subreports.
// object declarations
ISectionsPtr pSections = NULL;
ISectionPtr pSection = NULL;
IReportObjectsPtr pRepObjects = NULL;
IReportObjectPtr pRepObject = NULL;
ISubreportObjectPtr pSubObject = NULL;
IReportPtr pSubreport;

// get the number of sections in the report
pSections = spReport->GetSections();
//long count = 0;

// loop through each section in the report
for (long i = 1;i <= pSections->GetCount();i++)
{
// Create a variant to hold the value of i
VARIANT var2;
VariantInit(&var2);
var2.vt = VT_I2;
var2.lVal = i;
// pass the value of i to get the i-th section
pSection = pSections->GetItem(var2);
// get the report objects collection from the section
pRepObjects = pSection->GetReportObjects();

// as long as there are report object....
if (!pRepObjects->GetCount() == 0)
{
// ... loop through each
for (long j = 1;j <= pRepObjects->GetCount(); j++)
{
// Create a variant to hold the value of j
VARIANT var;
VariantInit(&var);
var.vt = VT_I4;
var.lVal = j;

// pass the value of j to the the j-th report object
pRepObject = pRepObjects->GetItem(var);

// if the report object is a subreport
if (pRepObject->GetKind() == crSubreportObject)
{
// re-assign the report object as a subreport object
pSubObject = pRepObject;

// to work with the subreport....
pSubreport = pSubObject->OpenSubreport();

CRYSTALCRAXDRT::IDatabasePtr spDB = pSubreport->GetDatabase();
hr = spDB->Tables->GetItem(_variant_t ((long)1))->SetLogOnInfo( bstrServer, bstrDatabase,bstrUserID,bstrPassword);

if(FAILED(hr))
return hr;


spDB->Tables->GetItem(_variant_t ((long)1))->Location = (_bstr_t)&quot;<tablename>&quot;;

}
}
}
}

return hr;

}

Cheers,
Techi
 
Thanks guys

I've found a bunch of functions on the CRPEJob class which should let me do what I want (GetNSubreportsInSection(), GetNthSubreportInSection(), GetSubreportInfo() and OpenSubreportJob()).

Hopefully these will do the trick - I'll need to use them in much the same way as you have both suggested.

(Now I know what the problem actually is, I stand a better chance of solving it)

Thanks again for taking the time to help

CMR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top