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!

setDataSource in Crystal Report form via code

Status
Not open for further replies.

PatMcLaughlin

Programmer
Dec 10, 2010
97
US
We have a crystal report form that is printed from time to time and called from VFP. When it was created, it used an XML created (Call it 'ABC.xml'). Now they want to change the name of the xml on each form printed... (Call it ABC123.xml) The actual xml has not changed, just the name. In VB.Net, we do this all the time with a FormName.SetDataSource(ABC123). I have had no luck doing the same thing in VFP. Any suggestions? The following code works as long as we use 'ABC.xml' but nothing in it passes the new xml to Crystal when we change the name:

Code:
		   loCrystal=CreateObject("CrystalRuntime.Application")
loReport=loCrystal.OpenReport(gcCrystalFiles + lcReport + ".rpt",1)
loReport.PaperOrientation = 2
loReport.DisplayProgressDialog = .F.
loReport.ReportTitle = (tcReportName)  
loReport.PaperSize = lnTray
IF lnDuplex1 > 1 Then
	loReport.PrinterDuplex = lnDuplex1
ENDIF
loReport.PrintOut(.F., INT((tnCopies)))
 
Couple of questions:

Where in there do you pass "ABC123" and I don't see any attempt at SetDataSource()?

 
Good morning Dan,
At this point, you are right, there is no attempt to pass it. That is my question as any attempt I have made to pass it has failed.​
 
Maybe all you need is copy the ABC123.xml to the same folder vfp currently refers to, if you pass over ABC.xml.

That old line setting data source to ABC.xml in VFP would need to change, maybe including full path to the XML file, something as simple as that.

Bye, Olaf.
 
Hi Olaf,
First it is encouraging that maybe I'm not as dumb as I think I am on this. Ha. The process used in creating the Crystal Report used ABC.xml as its data source initially. Now when it runs, I need to tell it to use ABC123 instead. In .net I use the 'SetDataSource' to tell it to use ABC123.xml...
Code:
crReport.SetDataSource("W:ABC123.xml")
I was hoping that it was similar in Foxpro
Pat
 
Why shouldn't it? Why don't you try?

W: seems to indicate drive W:\, right?
Try
loReport.SetDataSource("W:\ABC123.xml")
or if .NET W: means current folder of drive W, find out the full path and insert:
loReport.SetDataSource("W:\full\path\to\ABC123.xml")

If that function needs the path in unicode use STRCONV.

Bye, Olaf.
 
[tt]loReport.SetDataSource("W:ABC123.xml")[/tt] should be perfectly valid Foxpro code. What happens when you do that? Is there an error message, or what?

If all else fails, you could always programmatically rename the XML file back to the old name - the one that you say was working originally. But I can't imagine that would be necessary.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Try again... I meant to hit preview
Hi Mike,
It gives me 'OLE error code 0x80020006:Unknown name'
Pat
 
Olaf,
The W:\ refers to a drive which has been created for use with this program only. It is mapped on this network as a drive. As for trying it, I tryed many ways to do this. (As I said I feel better because what the experts are suggesting is what I have tried (so far)) I did not include my failed tries in the code I listed above because I knew it to fail and did not want to prejudice the answers.
 
The W:\ refers to a drive which has been created for use with this program only.

But that isn't what you're telling Crystal to look for:

loReport.SetDataSource("W:ABC123.xml")

That \ is REALLY important! Within VFP you can make assumptions like current working directory but for an external component you must be really exact about file locations.

 
Pat,

I just checked the RDC Help. If I've read it right, the code you need is something like this:

[tt]loReport.Database.SetDataSource("W\:ABC123.xml")[/tt]

I haven't been able to test that, so perhaps you could give it a try and report back.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hang on a moment. It might not be quite that simple. You might also need to set the following:

[tt]loReport.Database.tables(1).Name[/tt] (to name of XML file?)
[tt]loReport.Database.tables(1).DatabaseType[/tt] (1 = natively accessed, 2 = ODBC tables; don't know which one is XML)

and possibley some others. Sorry, but the Help is a bit vague on these.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike...
I tried those (and many variations of your suggestions to no avail. Adding .Database did allow the code to continue without error until it tried to print the Crystal Report, at which time it again wanted the xml name (In our example ABC.xml) used when creating the form.
 
When the Crystal Report was created, an xml file (W:\ABC.xml) was used as data. I pointed at it in Crystal Reports as ADO.net(XML). Now when I call for that report to be used, I am trying to pass the new xml (W:\ABC123.xml). Both XML's have the exact same structure, just the data changes. Using Visual Studio, we do this in the same way all the time by passing the 'SetDataSource' with the new dataset's name. I now need to do it in our Foxpro 9 app but have not had any luck.

The message that appears is 'ABC.xml not found' so apparently the new one is not being passed.
 
Please post the full .net and vfp code for us to compare, not just the single line.

In the end you're using the same Crystal report classes with the same objects and methods. But if you write SetDataSource("somename.xml") in .NET the string is unicode, not so in VFP. This is where differences begin, that are not even visible.

You might be doing this on the wrong object of crystal reports, if its message says it still looks for ABC.xml

Bye, Olaf.
 
Good Morning Olaf,
I tried the Unicode without success too. Here is the code from VFP and then DotNet. Some differences in the code i.e. the VFP changes the orientation and passes a value for ReportTitle etc.

VFP

Code:
loCrystal=CreateObject("CrystalRuntime.Application")
*loReport=loCrystal.OpenReport("h:\CrystalReports\" + lcReport + ".rpt",1)
loReport=loCrystal.OpenReport(gcCrystalFiles + lcReport + ".rpt",1)
=SetDefaultPrinter(lcPName)
loReport.Database.SetDataSource(STRCONV(lxReportXML,6))
**loReport.Database.Name(lxReportXML)
**loReport.Database.Tables(1).DatabaseTypeName(1)
loReport.PaperOrientation = 2
loReport.DisplayProgressDialog = .F.
loReport.ReportTitle = (tcReportName)  && "Recall Report"
loReport.PaperSize = lnTray
IF lnDuplex1 > 1 Then
   loReport.PrinterDuplex = lnDuplex1
ENDIF
loReport.PrintOut(.F., INT((tnCopies)))

.Net

Code:
crCustStudyRpt1.PrintOptions.PrinterName = gPrinter
crCustStudyRpt1.SetDataSource(CustStudyRptDS1)
crCustStudyRpt1.Refresh()
crCustStudyRpt1.PrintToPrinter(1, False, 0, 0)
 
Olaf... To further define etc.

Please understand that the code in the VFP is not the only one I have tried... Just the last one. I have tried many variations of both yours and Mikes suggestions. i.e. the STRCONV conversion setting is not likely '6' but that is the last one tried before the copy. lxReportXML = "W:\NameOfXML.xml
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top