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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting parameter from C++/Win32 application

Status
Not open for further replies.

kedrew

Programmer
Jun 22, 2001
29
US
I have created a report in Crystal Reports v8.5 that contains a parameter for a stored procedure.

I need to set the parameter programmatically from a C++/Win32 application.

The sample file from Seagate/Crystal for "pro salaries" does not contain information specific to parameters, and most of the documentation from a C++ standpoint is scarce.

Any help or pointers to a source would be greatly appreciated, thanks.
 
this may help... you need to do all the report , object setup etc

long john, objCount;
_bstr_t ParameterFldName;
IParameterFieldDefinitionsPtr pParameterFields = 0;
IParameterFieldDefinitionPtr pParameterField = 0;
HRESULT hr = m_Report->get_ParameterFields((IParameterFieldDefinitions **) &pParameterFields );
ASSERT(SUCCEEDED(hr));


pParameterFields->get_Count(&objCount);
for (john = 1; john <= objCount; john++)
{

pParameterFields->get_Item(john, (IParameterFieldDefinition**) &pParameterField);
ParameterFldName = pParameterField->GetParameterFieldName();;
_bstr_t spParameterValue = _bstr_t(m_Str_Customer);
if(ParameterFldName == _bstr_t(&quot;@param1&quot;)) // that is what it is called now!!!
pParameterField->AddCurrentValue(spParameterValue);
}

I actually think there is a knowledge base article from their web site with a bit of this stuff!!! also look at the .tli and .tlh files I used those to work this out. I think this also suppresses the report viewer asking for the default parameter.
it is actually quite easy once you work your way thru all the VB distractions. You have my sympathies Crystal and Visual C++ are not great bed partners. I started this program that was trivial from the C++ point of view, but printing a simple invoice print program using the RDC is proving a real test. Good luck!!

 
Hi John,


I know this thread was long ago...
But have you ever tried this with subreports?
It doesn't work. Could you help me?

Greetings,
Sue
 
Here's my problem: I have a main report which is used just as container report. It contains many subreports. Each of those has a parameter field which should be filled in by our C++ method (We do not want to show the standard parameter dialog from Crystal, the user should not know about those parameters).

One of those subreports contains a second parameter field which should be filled in by the user when he calls the report.

The user should have the possibility to call the individual subreports standalone, but he should also have the possibility to call the main report containing all subreports.

The call to set the parameter (AddCurrentValue()) does not work for those subreports. In the ParameterFieldDefinition-Object the parameters are set, but the report does not show any data.

If we call the method SetEnableParameterPromting(true), the normal Crystal Report parameter dialog is shown and everything is okay. Just the call of AddCurrentValue(SetEnableParameterPromting(false)) causes nothing.

-> :-(

Thanks for each kind of help.
 
Hi Susanne,

Are you setting the parameter to the subreports? I mean. are you getting the subreport from the main report, opening the subreport. Then accessing the IParameterDefinition object and setting the values to it?
From the main Report object, you have to get a handle to each of the subreports, open the report, set the parameters, Open the database connection then set the location. Hope this helps. Let me know.

Here 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_FALSE;

// 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::IParameterFieldDefinitionsPtr pParameters = pReport->ParameterFields;

//: walk all of the crystal parameters in the report
long lCount = pParameters->GetCount();
CString sParamName;
CString sParamValue;

for(int i=1; i<=lCount; i++)
{
CRYSTALCRAXDRT::IParameterFieldDefinitionPtr pParameter = pParameters->GetItem(i);

sParamName = pParameter->GetParameterFieldName();


if ( sName.CompareNoCase( csParamName ) == 0 )
{
//: set the value for crystal

if ( SetCrystalParameterForCrystal
)
{
//: move on to the next
break;
}
}
}

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 = varDataSource.bstrVal

}
}
}
}

return hr;

}
 
Hi Techies,

thank you very much for your reply...

But: It doesn't work correctly for my kind of problem. I think the problem is, that the parameters are located in the subreports. I'm not able to pass the values to those subreport parameters.

Do you or anybody else have any further suggestions?

:-( :-( :-( :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top