Solved

Crystal Reports VB6

Posted on 2014-04-03
11
1,056 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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