Solved

Crystal Reports VB.net 2010

Posted on 2014-11-07
17
630 Views
Last Modified: 2014-11-13
Hello Experts,

I am rewriting an app in VB.net from VB6. Here is my code to generate a Crystal Report in VB6. I cant get figure out how to make this work in VB.net 2010. Can someone point me in the right direction?

Private Sub SetReportLocation(ByRef RepObj As CRAXDRT.Report)

    Dim CrxDDF As CRAXDRT.DatabaseTable
    Dim CP As CRAXDRT.ConnectionProperties

    For Each CrxDDF In RepObj.Database.Tables
        Set CP = CrxDDF.ConnectionProperties
        CP.DeleteAll
        CP.Add "ConnectionString", "Driver={SQL Anywhere 10};Uid=user;Pwd=password;DSN=sqlbase;"

    Next

    Set CrxDDF = Nothing
    Set CP = Nothing

End Sub


Private Sub cmd_Print_Click()

Dim DetailPrnt As VbMsgBoxResult
Dim crxApp As CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report

DetailPrnt = MsgBox("Would you like a detailed print?", vbYesNo, "Detailed?")

If DetailPrnt = vbYes Then
    Set crxApp = New CRAXDRT.Application
    Set crxRpt = crxApp.OpenReport(App.Path & "\Reports\DetailRecpt.rpt")
    SetReportLocation crxRpt
    crxRpt.ParameterFields(1).AddCurrentValue (txt_Transact.Text)
Else
    Set crxApp = New CRAXDRT.Application
    Set crxRpt = crxApp.OpenReport(App.Path & "\Reports\StdRecpt.rpt")
    SetReportLocation crxRpt
    crxRpt.ParameterFields(1).AddCurrentValue (txt_Transact.Text)
End If

'To View the report
frm_Report.Show
frm_Report.CRViewer.ReportSource = crxRpt
frm_Report.CRViewer.ViewReport



End Sub

Open in new window

0
Comment
Question by:triphen
  • 8
  • 5
  • 3
  • +1
17 Comments
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40428280
You can't make that code work in VB2010.

The RDC (CRAXDRT) has been replaced with .Net assemblies and won't work.  It is still available on your system for some kind of backwards compatibility.

You need to download Crystal for VS2010
http://scn.sap.com/people/coy.yonce/blog/2010/11/12/crystal-reports-for-visual-studio-2010-production-release-now-available

Here is a document that explains how to migrate from the RDC to .Net
http://scn.sap.com/docs/DOC-21971

http://msdn.microsoft.com/en-us/library/ms225492(v=vs.80).aspx

mlmcc
0
 
LVL 18

Assisted Solution

by:vasto
vasto earned 56 total points
ID: 40428774
Agree. Some basic features in CRAXDRT might be working in VB.NET, but there will be tons of problems and as far as I know the license is not allowing it.
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
ID: 40429371
you better try the version of CR that is specifically built for .Net. Have a look at http://emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:triphen
ID: 40429518
Thanks for the feedback...I downloaded Crystal for VS2010, but still kind of lost :/

How do I set my connection string? How do I pass parameters?
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
ID: 40429749
did you check my article?
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40430240
Since you had it working with CRAXDRT did you check the article on converting to the .Net assemblies?

mlmcc
0
 

Author Comment

by:triphen
ID: 40432023
I read both articles, but it is still unclear on where to put my connection string. Can you point me in the right direction?
0
 

Author Comment

by:triphen
ID: 40432032
This is my current code:

Dim cryRpt As New ReportDocument
cryRpt.Load("C:\Reports\Report.rpt")
CrystalReportViewer1.ReportSource = cryRpt

Open in new window


All this is doing is loading the RPT file in the CrystalReportViewer1, and it appears to load data that was saved to the actual RPT file when the RPT was first created. I catn figureout how to make it connect to the DSN using this connection string:

"Driver={SQL Anywhere 10};Uid=user;Pwd=password;DSN=sqlbase;"
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
ID: 40432416
instead of having the report connect to the server, I push a data set already filled to the report.
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40432769
What version of Crystal are you using?

If it is a standalone version, does the report run from the designer?

Have you tried to refresh the report?


mlmcc
0
 

Author Comment

by:triphen
ID: 40434233
When I added "CrystalReportViewer1.RefreshReport()" I get a prompt for my Crystal Reports parameters, then a prompt for login credentials. See attached.

Dim cryRpt As New ReportDocument
       cryRpt.Load("C:\Reports\Report.rpt")
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.RefreshReport()

Open in new window

0
 

Author Comment

by:triphen
ID: 40434234
I think CR13, but how can I check the exact version?
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40434273
Do you design in the VS IDE or a separate program?

IN the standalone version it is under HELP --> ABOUT CRYSTAL

mlmcc
0
 

Author Comment

by:triphen
ID: 40434277
I am designing the report in a completely separate program. See attached.

Then I am trying to open it using a Windows Form applciation on VS 2010 VB.net
0
 

Author Comment

by:triphen
ID: 40434420
So I got it to login and pass a parameter, but for some reason on loading of the report, I get a prompt that asks me for the parameter again?

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1



   
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument



        cryRpt.Load("C:\Reports\StdRecpt.rpt")


        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = "71744"
        crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("Transact")
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)


        CrystalReportViewer1.ReportSource = cryRpt
        cryRpt.SetDatabaseLogon("user", "password", "sqlbase", "")
        CrystalReportViewer1.RefreshReport()
End Sub

Open in new window

0
 
LVL 100

Accepted Solution

by:
mlmcc earned 277 total points
ID: 40434962
Which version of Crystal?

Don't do a refresh.  That causes Crystal to discard the parameters and prompt again.

Make sure the report is NOT saved with data
Open the report
Click FILE
Uncheck SAVE DATA WITH REPORT

mlmcc
0
 

Author Comment

by:triphen
ID: 40442024
THIS WORKED!!!!


        Dim cryRpt As New ReportDocument
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        cryRpt.Load("C:\Reports\StdRecpt.rpt")

        crParameterDiscreteValue.Value = "71745"
        crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("Transact")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        CrystalReportViewer1.ReportSource = cryRpt

        cryRpt.SetDatabaseLogon("username", "password", "DSN NAME", "")
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
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…
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…

821 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