• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1247
  • Last Modified:

Crystal Reports VB6

Hello Experts,

I have a simple Crystal Reports with only one parameter (TransNum). I am trying to launch my report from VB6 and pass that parameter. I am having some issues, here is my code:

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

Set crxApp = New CRAXDRT.Application
Set crxRpt = crxApp.OpenReport("C:\Applications\Receipt.rpt")



'To View the report
CRViewer.ReportSource = crxRpt
CRViewer.ViewReport
crxRpt.ParameterFields(0) = "@TransNum;" & "2001" & ";TRUE"

Open in new window



I get 2 errors...

#1
Run-Time error '-2147352565 (8002000b)':

Debug shows this line: crxRpt.ParameterFields(0) = "@TransNum;" & "2001" & ";TRUE"



#2
---------------------------
Crystal Report Viewer
---------------------------
Logon failed.
Details: 28000:[Sybase][ODBC Driver][SQL Anywhere]Invalid user ID or password [Database Vendor Code: -103 ]
---------------------------
OK  
---------------------------



Is there a way to save the login information to the SyBase SQL database within the report? OR how can I include it within my VB code?

Thoughts....?
0
triphen
Asked:
triphen
  • 7
  • 2
  • 2
1 Solution
 
triphenAuthor Commented:
Maybe this will help my login question?

"Driver={SQL Anywhere 10};Password=password;Persist Security Info=True;User ID=dba;Data Source=sqlbase;Location=sqlbase"

I just don't know the exact syntax in VB :/
0
 
Deepak LakkadCommented:
Hi,

Which database do you using ?

I have a VB6 application in which I use following code to show reports

' Declaration Section
Dim cApplication As New CRPEAuto.Application          ' Application
Dim cReport As CRPEAuto.Report                        ' Structure of Report
Dim cParameters As CRPEAuto.ParameterFieldDefinitions ' Collection of Parameters
Dim cParameter As CRPEAuto.ParameterFieldDefinition   ' One Parameter
Dim PreviewOption As CRPEAuto.PrintWindowOptions      ' Options for Preview Window

'Button's Click event to view report
Private Sub cmdOk_Click()
On Error GoTo errZone
    ' Database Path
    Dim mDatabase As String
    Dim I As Integer
    
    If UCase(Trim(gYear)) = "DEFAULT" Then
        mDatabase = "ABC.MDB"
    Else
        mDatabase = UCase(Trim(gYear)) & ".mdb"
    End If
    
    varPeriod = "Bill No - From " & txtFromBill.Text & " To " & txtToBill.Text
    
    varTitle = "Government Luxury Tax"
        
    Set cReport = cApplication.OpenReport(App.Path & "\TheReport.rpt")
    
    ' Change Location of Table
    For I = 1 To cReport.Database.Tables.Count
        cReport.Database.Tables(I).Location = App.Path & "\" & mDatabase
    Next I
    
    cReport.RecordSelectionFormula = "{MasterBillMaster.MasterBillNo} in " & txtFromBill.Text & " to " & txtToBill.Text
    
    Set cParameters = cReport.ParameterFields
    For Each cParameter In cParameters
        Select Case UCase(cParameter.Name)
            Case "{?COMPNAME}"
                cParameter.SetCurrentValue "Hotel Maruti"
            Case "{?PERIOD}"
                cParameter.SetCurrentValue varPeriod
        End Select
    Next
        
    If optPreview.Value = True Then
        Set PreviewOption = cReport.PrintWindowOptions
        PreviewOption.HasCloseButton = True
        PreviewOption.HasRefreshButton = True
        PreviewOption.HasExportButton = True
        PreviewOption.HasPrintSetupButton = True
        PreviewOption.HasPrintButton = True
        
        cReport.Preview varTitle, 0, 0, 800, 600   ', WS_MAXIMIZE Or WS_MINIMIZEBOX Or WS_MAXIMIZE Or WS_MINIMIZEBOX
    ElseIf optPrint.Value = True Then
        cReport.PrintOut False, 1, False
    End If
    
    Exit Sub
errZone:
    MsgBox "Unable to view report ...", vbInformation, gMsg
    MsgBox Err.Description
End Sub

Open in new window


This code is working fine for me ...
0
 
triphenAuthor Commented:
Database = SyBase SQL Anywhere v10
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Deepak LakkadCommented:
Hi,

Here is another code block which having SetReportLocation() to set connection properties ...

Please check it

Private Sub cmdSetLocations_Click()
    Dim CrxApp As New CRAXDRT.Application
    Dim CrxRep As CRAXDRT.Report
    Dim CrxSubRep As CRAXDRT.Report

    Dim strReport As String
    Dim i As Integer, ii As Integer

    strReport = "[Path to report file]"
    Set CrxRep = CrxApp.OpenReport(strReport)

    SetReportLocation CrxRep

    For i = 1 To CrxRep.Sections.Count
        For ii = 1 To CrxRep.Sections(i).ReportObjects.Count
            If CrxRep.Sections(i).ReportObjects(ii).Kind = crSubreportObject Then
                Set CrxSubRep = CrxRep.OpenSubreport(CrxRep.Sections(i).ReportObjects(ii).SubreportName)
                SetReportLocation CrxSubRep
            End If
        Next ii
    Next

    'open your report in the report viewer

    Set CrxApp = Nothing
    Set CrxRep = Nothing
    Set CrxSubRep = Nothing
End Sub

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 "Connection String", "[Your connection string goes here]"
    Next

    Set CrxDDF = Nothing
    Set CP = Nothing

End Sub

Open in new window

0
 
mlmccCommented:
To answer your first question, no you cannot store the userid/password in the report.  This is for security reasons since if you could the potential is there for someone to use that to access the database.

What version of Crystal are you using?

mlmcc
0
 
triphenAuthor Commented:
Crystal Reports XI
0
 
mlmccCommented:
What code are you using now?

mlmcc
0
 
triphenAuthor Commented:
It's in the original post.

I am trying to run this report (C:\Applications\Receipt.rpt)
Pass this parameter TRANSACT with value of 2001
0
 
triphenAuthor Commented:
This worked!!!

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


Set crxApp = New CRAXDRT.Application
Set crxRpt = crxApp.OpenReport(App.Path & "\Report.rpt")
crxRpt.ParameterFields(1).AddCurrentValue (txt_Transact.Text)


frm_Report.Show
frm_Report.CRViewer.ReportSource = crxRpt
frm_Report.CRViewer.ViewReport

Open in new window

0
 
triphenAuthor Commented:
Here is the connection string that worked with this report code:

CP.Add "ConnectionString", "Driver={SQL Anywhere 10};Uid=reportuser;Pwd=pixel1047;DSN=pixelsqlbase;"
0
 
triphenAuthor Commented:
I was able to make it work researching on Google.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now