Solved

Visual Basic, Crystal Reports and RDC

Posted on 2001-07-02
1
334 Views
Last Modified: 2013-11-25
I need some help with a problem using RDC with Visual Basic.  My environment is Visual Basic 6.0 and Crystal Report 8.5.  I want to build a simple report that uses either unbound fields and/or formula fields.  then at runtime have the fields populated for a simple tabular column report to a SQL Server database. Most of the Examples Crystal Reports provide use an MDB file and are useless for client/server.  I have purposely kept this example simple.  I am trying to connect to a stored procedure with no parameters in it.

The designer builds the following code behind the form with the form with the Crystal Reports viewer on it to which I added the ADO code for connecting to SQL Server:

Dim Report As New CrystalReport1

Private Sub Form_Load()

Dim strCon As String
Dim adoTest As New ADODB.Connection
Dim adoCmd As New ADODB.Command

Screen.MousePointer = vbHourglass

strCon = "DSN=dsnTest; UID=userx; PWD=abcd;"
        With adoTest
            .ConnectionString = strCon
            .ConnectionTimeout = 60
            .Open
            .CursorLocation = adUseClient
        End With
       
        With adoCmd
            .CommandText = "usp_Test"
            .CommandType = adCmdTable
        End With

CRViewer1.ReportSource = Report
CRViewer1.ViewReport

Screen.MousePointer = vbDefault

End Sub

Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth

End Sub


Now I am having a hard time knowing how to connect the dots and populate the report.  I have tried creating recordsets and looping through them to populate the report. I have tried inserting the loop into section shown below in the designer object.  The best I can do is get one record to display in the detail section.

Private Sub Section10_Format(ByVal pFormattingInfo As Object)

End Sub

Any help I can get to connect the dots and make this run would be greatly appreciated.

   
       
0
Comment
Question by:lbsaltzman
1 Comment
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 200 total points
ID: 6245910
You must create a TTX (Data Definition) file and base your report design from it in Crystal Designer.  A TTX file is a tab delimited text file which specifies how your dataset will look.  A simple example might be:

OrderID<tab>long<tab>1
OAmount<tab>currency<tab>1.00
CustID<tab>long<tab>1
ODate<tab>date<tab>Jan 5, 2001
OMsg<tab>string<tab>20<tab>string sample value

Field 1 is the field name, 2 is the type, 3 is either the field size or a numeric example, and 4 is a string example.  You could use the Data Definition Tool in CRW, but notepad is much more efficient.

The Active Data driver is P2SMON.DLL

I haven't upgraded to 8.5, but in 8.0 using the Report Expert, you would select More Data Sources, Active Data, Active Data (Field Defs Only) and browse for your TTX file.

Design your report

At runtime, plug your ADO dataset into the RDC report by

dim crAppl as CRAXDRT.Application
dim crRep as CRAXDRT.Report
dim rs as ADODB.Recordset

' bunch of code to setup your recordset and load the data into it

set crAppl = new CRAXDRT.Application
set crRep = crAppl.OpenReport("C:\path\report.rpt")
' Set ADO recordset to first table in report
crRep.Database.Tables(1).SetDataSource rs, 3
' Be sure to insert a CR Smart Viewer on form and then
crViewer1.ReportSource = crRep
crViewer1.ViewReport

Let me know if you are using the CRPEAuto modules because the code is different.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question