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

Passing Parameter from Visual Basic to Crystal Report 2

Status
Not open for further replies.

xterra

Programmer
Apr 5, 2001
71
US
How do I do this? I tried using a parameter field but I can't find a way to pass it a value from VB. I have looked everywhere but nothing helps. I tried report.parameterfield(1).setcurrentvalue but that doesn't give any value. Any ideas this is driving me nuts.

thanks,

Adam
 
I tried that already and it does have a value when I do getnthcurrentvalue but the problem is it doesn't have a value in Crystal Reports. I tried linking them with the fields but It won't let me. It doesn't show any fields in the dropdown box to the left where you tell it what field to use to link in the subreport. I have just built a file and did it that way, but that is not the most efficient way of doing it. I have been working on this solid for 2 weeks and can't get it to work so I guess I will have to use the less efficient method.

Thanks though,

Adam
 
Sorry I could help you sooner, I was whiped out all week with a nasty cold. anyways, a few things to try.

1. Make sure you have a date parameter on your sub report.
2. Make sure your formula field on your main report is set to get the date value of the string you passed to your string parameter.
3. Make sure the Subreport Parameter is Linked to the Report Formula.

when you open the subreport linking window. you select the formula from then left hand list box, should be @FormulaName
add it to the list on the right. the lower right combo box will become greyed out. look at the left combo box, if you hit the down arrow, it will either look empty or have some weird ?pm.whatever thing in it. if you look really close on the right hand side of the drop down list, there are scroll arrows there (it's a freak bug that CR knows about) scrolly down until you see the ?ParamName from your sub report.

that should get the parameters to the sub report. then you can use the selection expert to create a fomula off of them. mine looks like:
{dao_OS_Sent_Date} >={?Startdate} and
{dao_OS_Sent_Date} <={?EndDate}

hope it helps.

oh, if you're not sure your parameter values have the value correctly, put them on your report header, the value should show up on your preview. Also, one last thing, when I passed a date in, I passed it as &quot;YYYY,MM,DD&quot; instead of a standard date format.

I am still curious how the got the coke'd up monkeys to put this thing together. every once and a while, it works wonderfully, but most of the time, it's just one royal pita.
 
LOL I agree those Guys at Crystal didn't sit down and think this thing over very well. I see what you are saying now about the linking it is buggy and that is why I was missing it. So I have them linked and It should work but when I put the parameter in the Report Header to show the value I get nothing. So now I am back to that problem, but you did solve the linking problem I was having. Here is my code now

Report.ParameterFields(1).AddCurrentValue CStr(DateValue)

I open the immediate windows and print .GetNthCurrentValue(1) and it is the date I gave it. Also there is one thing, I am turning EnableParameterPrompting off does that make a difference? Again I am using Version 8.0 Thanks I am so close now except this one thing.

Adam
 
EnableParameterPrompting just tells CR wether or not to prompt for a value if nothing is passed. try turning it on and not setting the value of the parameter. it should pop up the generic CR common dialog for value prompting, if you enter a value and it still doesn't show up in the report header, I'd say goto the CR home office with a baseball bat and start demanding fixes.

-Rick
 
LOL I'm glad you make me laugh or I'd go crazy. You want to help me if I do go beat those people up :) Ok if I enable the parameter prompting and enter a value with CR's value propmpting thing, it works. But If my value was getting to CR then it shouldn't pop up right? If that is true then something is wrong with getting the value from VB to CR because I am doing everything that it tells you to do.

Adam
 
Okay, so CR 8.0 does suck more then 8.5. heheh, well, lets try this another way...

you can try opening the subreport object itself and setting the parameters on the subreport. it would look something like:

Dim crxTables As CRAXDRT.DatabaseTables
Dim crxTable As CRAXDRT.DatabaseTable
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim crxSubReportObj As CRAXDRT.SubreportObject
Dim crxReportObjs As CRAXDRT.ReportObjects
Dim crxSubReport As CRAXDRT.Report
Dim ReportObject As Object

Set crxSections = Report.Sections
For Each crxSection In crxSections
Set crxReportObjs = crxSection.ReportObjects
For Each ReportObject In crxReportObjs
If ReportObject.Kind = crSubreportObject Then
Set crxSubReportObj = ReportObject
Set crxSubReport = crxSubReportObj.OpenSubreport

'--
with crxsubreport.parameterfields(1)
.ClearCurrentValueAndRange
.DiscreteOrRangeKind = crDiscreteValue
.AddCurrentValue Year(Now) & &quot;,&quot; & Month(Now) & &quot;,&quot; & Day(Now) + 1
end with
'--

End If
Next ReportObject
Next crxSection


now please mind that I haven't done it this way, so I'm not sure if it'll take the date format, you may have to once again have parameter(1) be a string and then use a formula field to convert it, but this time it will all be on the sub report.
 
Thanks, but I just dediced to write the date's to a database file and use the database field in my formula. My client has to have this soon and I am running out of time so I had to do it the more inefficient way (which I hate doing) but it works. Thanks for all your help though, I wish there was something I could do to help ya because of all of your time I have taken up.

Thanks again,

Adam

P.S. If any CR Programmers are reading this, go get a job at AOL. If you program as badly for them as you do for CR then you can do us all a favor and put them out of business :) there I blew off some steam.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top