Solved

Visual Basic, Crystal Reports and RDC

Posted on 2001-07-02
1
331 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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now