Solved

Visual Basic, Crystal Reports and RDC

Posted on 2001-07-02
1
332 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

14 Experts available now in Live!

Get 1:1 Help Now