Avatar of rborda
rborda
Flag for United States of America

asked on 

MS Access programatically open Crystal Report Viewer XI to display a rpt report

I successfully created an rpt file and saved with data.
But I need to display this report using Crystal Report Viewer XI application thru MSAcess 2003.
Could you tell me if I am missing a reference in MS Access; and how to declare correctly the variable?

I marked ????**** in the following code where my problem resides.

Thank you in advance.
Dim crrpt As New CRAXDRT.Report
    Dim crapp As New CRAXDRT.Application
????****Is CRViewer declared correctly?
    Dim CRViewer11 As New CrystalActiveXReportViewer
    Dim myParamField As CRAXDRT.ParameterFieldDefinition
    Dim intCounterPartyId, intNoCreditLimit, intAllAccounts, intOpenTrades, intOpenFail, intOpenOver As Integer
    Dim dtFirstDayOfYear As Date
    Dim dblCreditUsed, dblYTDAmount As Double
    Dim db As Database, rs As Recordset, strSql, strFileName, strMsg As String
    Dim strAttachDir, strAttachment, strReportDir, strCrReport As String
    
    'Set db = CurrentDb
    
    strAttachDir = "T:\Work\"
    
    'open crystal report(rpt)
    strReportDir = "T:\Work\"
    strCrReport = "TimeDetailwithData.rpt"
    Set crrpt = crapp.OpenReport(strReportDir & strCrReport)
    strFileName = Format(Now(), "YYYY-MM-DD-HHMM") & "-TimeDetail.rpt"
    strAttachment = strAttachDir & strFileName
    
    
    crrpt.DiscardSavedData
    
    'SET PARAMETER FIELDS
    Set myParamFields = crrpt.ParameterFields
    For Each myParamField In myParamFields
        With myParamField
            Select Case .ParameterFieldName
                    Case "StartPeriod"
                        .SetCurrentValue CDate("2008-7-16")
                    Case "EndPeriod"
                        .SetCurrentValue CDate("2008-7-17")
                    Case "Org - Comp"
                        .SetCurrentValue "2WV"
                    Case "Org - Dpt"
                        .SetCurrentValue "300"
                    Case "Org - Fac"
                        .SetCurrentValue "01302"
            End Select
        End With
    Next
    crrpt.EnableParameterPrompting = False
    
    crrpt.ExportOptions.FormatType = crEFTCrystalReport70
    crrpt.ExportOptions.DestinationType = crEDTDiskFile
    crrpt.ExportOptions.DiskFileName = strAttachment
    crrpt.Export False
    
????****PROBLEM HERE... I can't open Crystal Report Viewer XI with report previously created
    CRViewer11.ReportSource = strAttachment
    CRViewer11.ViewReport

Open in new window

DB Reporting ToolsCrystal ReportsMicrosoft Access

Avatar of undefined
Last Comment
rborda

8/22/2022 - Mon