Hi Guys
I call a few reports from VB6 but always using the mdb file it was created with.
Now I have two mdb databases containing exactly the same fields but holding different data. How do I pass the filename that the report must use to the report? Sometimes I want the data that's in abc.mdb and sometimes the data that's in def.mdb. Maybe later there will be a ghi.mdb and jkl.mdb etc...
Any help greatly appreciated.
BezzieWhich tool or programming language you are using to do so ? Is it VB , .net or Java ?
Thanks|||Hi
I'm calling the Reports (Crystal Reports 8) from a Visual Basic 6 application.
Bezzie|||Hello Bezzie,
Let me reiterate what you are planning to do.
You have a report created in crystal 8.0 using abc.mdb. Now using VB application you want to switch the database at runtime in such a way that if you want to see data from def.mdb or ghi.mdb you need to be able to do that.
To achieve this goal what you need to do is
1. Create report using abc.mdb.
2. Write VB code to reset connection information at runtime.
3. Preview report.
We need to explore step 2 before that I would like to know are we on same page, so far so good ?
THanks|||Hi Dilemma
Yes. The program I'm working on is a genetic calculator for birds. I previously had only one mdb file that held all the info I needed on my reports.
I've started to add additional species to the program so changed my mdb so that I have a mdb with the userdata, and then one mdb for each species of bird.
The userdata.mdb will allways be in use throughout the program but there is a different mdb for each species of bird with the species specific data.
So when the user select to work with species ABC I need to pass the ABC.mdb with the data of species ABC and when he select species DEF I need to pass DEF.mdb etc. Those bird specific databases might become more and more as the species is added to the program so that's why I need to keep them separate, and why I don't want to create a separate report for each species of bird as the report will be exactly the same for each species but with a different set of data!
Bezzie|||You need to code something like this. Let me findout ODBC's example. Meanwhile I would like you to get familiar with this code.
How to connect to an OLEDB data source
This example demonstrates how to connect to an OLEDB (ADO) data source, change the data source, and change the database by using the ConnectionProperty Object, as well as how to change the table name by using the Location property of the DatabaseTable Object,. CrystalReport1 is created using an ODBC data source connected to the pubs database on Microsoft SQL Server. The report is based off the authors table.
' Create a new instance of the report.
Dim Report As New CrystalReport1
Private Sub Form_Load()
' Declare a ConnectionProperty object.
Dim CPProperty As CRAXDRT.ConnectionProperty
' Declare a DatabaseTable object.
Dim DBTable As CRAXDRT.DatabaseTable
' Get the first table in the report.
Set DBTable = Report.Database.Tables(1)
' Get the "Data Source" property from the
' ConnectionProperties collection.
Set CPProperty = DBTable.ConnectionProperties("Data Source")
' Set the new data source (server name).
' Note: You do not need to set this property if
' you are using the same data source.
CPProperty.Value = "Server2"
' Get the "User ID" property from the
' ConnectionProperties collection.
Set CPProperty = DBTable.ConnectionProperties("User ID")
' Set the user name.
' Note: You do not need to set this property if
' you are using the same user name.
CPProperty.Value = "UserName"
' Get the "Password" property from the
' ConnectionProperties collection.
Set CPProperty = DBTable.ConnectionProperties("Password")
' Set the password.
' Note: You must always set the password if one is
' required.
CPProperty.Value = "Password"
' Get the "Initial Catalog" (database name) property from the
' ConnectionProperties collection.
' Note: You do not need to set this property if
' you are using the same database.
Set CPProperty = DBTable.ConnectionProperties("Initial Catalog")
' Set the new database name.
CPProperty.Value = "master"
' Set the new table name.
DBTable.Location = "authors2"
Screen.MousePointer = vbHourglass
' Set the report source of the viewer and view the report.
CRViewer91.ReportSource = Report
CRViewer91.ViewReport
Screen.MousePointer = vbDefault
End Sub
Thanks|||Hi Dilemma
Thanks for the trouble. I got it to work with Datafiles Property.
Bezzie|||Excellent Job.
Thanks
Dilemma
Monday, February 20, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment