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!

Changing Crystal Report DBase Connection 2

Status
Not open for further replies.

Lynus

Technical User
Apr 12, 2003
69
0
0
I created a report in CR8. I connected it to a temporary database during design to pull the fields I needed. It is complete and saved. Now I go into VB and I add the CR object and display the report thusly:

CR1.ReportFileName = App.Path & "\ChaPrint.rpt"
CR1.Action = 1

So my problem is that it is still hinged to the temporary database. How would I go setting up an object that ties to the chaprint report and then manipulating the reports connections???


Any help appreciated.
Thanks.
 
Depends on the data source. If, for instance, you're connecting to an Access database natively, you would set the OCX control's Datafiles property at runtime like this:

CrystalReport1.Datafiles(0) = "c:\MyProductionDatabase.mdb"

If that's not what you're after, check out this document on, among other things, connecting, changing servers, changing databases, changing tables, and multiple logons:

-dave
 
Well you see.... Heres the problem. Yes I am using an Access database. I am only using the Crystl32.ocx object on the application. I can manipulate the OCX properties but how does changing the OCX properties manipulate the database connections of the actual RPT file?????
 
Ok so I am a little confused. How does changing the application control alter the connection for the report? I am only calling the report and running it with the object arent I? My apologies for the remedial questions but I am a CR newbie. Thanks.
 
If all you're trying to accomplish is for the report to get the data from the correct data source at runtime, then just use the method I described in my first post:

CR1.ReportFileName = App.Path & "\ChaPrint.rpt"
CR1.Datafiles(0) = "c:\PathToYourDB\YourDB.mdb"
CR1.Action = 1

-dave




 
Thanks Dave. One last question. The report in question has 8 subreports in it as well. I notice the Datafiles(0). Is the 0 the index for the report? Should I do something like this???

Dim r as integer
for r = 0 to 7
CR1.Datafiles(r) = "c:\mypath\mydb"
next


Thanks for the help.
 
You're on the right track. Try something like this:
[tt]
Dim X As Integer, Y As Integer

CR1.ReportFileName = App.Path & "\ChaPrint.rpt"

'Get the number of subreports
Y = CR1.GetNSubreports - 1

'Set the datasource location for the main report
CR1.DataFiles(0) = "c:\mypath\mydb"

'Set the datasource location for the subreports
For X = 0 To Y
CR1.SubreportToChange = CR1.GetNthSubreportName(X)
CR1.DataFiles(0) = "c:\mypath\mydb"
Next X

CR1.Action = 1
[/tt]
There's a whitepaper on this as well:

-dave
 
You are the best!!! Thanks for the help Dave, That worked like a charm. I gave you another star :) Thanks for all the help.
 
Where in Crystal do you add the code to change the path?

I want to use the following
CrystalReport1.DataFiles(0) ="TableA"
CrystalReport1.DataFiles(1) ="TableB"
CrystalReport1.Action = 1

In the report when I am passed a value from another programmer, They will tell me what Table to use either A or B...

Where do I put this in Crystal Reports Ver 10?

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top