Solved

Crystal Reports VB6

Posted on 2014-04-03
11
1,019 Views
Last Modified: 2014-04-09
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
Comment
Question by:triphen
  • 7
  • 2
  • 2
11 Comments
 

Author Comment

by:triphen
ID: 39977112
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
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 39977196
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
 

Author Comment

by:triphen
ID: 39977226
Database = SyBase SQL Anywhere v10
0
 
LVL 11

Expert Comment

by:Deepak Lakkad
ID: 39977258
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 39977962
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
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.

 

Author Comment

by:triphen
ID: 39978816
Crystal Reports XI
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 39979191
What code are you using now?

mlmcc
0
 

Author Comment

by:triphen
ID: 39979197
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
 

Accepted Solution

by:
triphen earned 0 total points
ID: 39979645
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
 

Author Comment

by:triphen
ID: 39985287
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
 

Author Closing Comment

by:triphen
ID: 39988245
I was able to make it work researching on Google.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

706 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

21 Experts available now in Live!

Get 1:1 Help Now