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....?
triphenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.