Results 1 to 12 of 12

Thread: Crystal Report 9.0 and VB6

Threaded View

  1. #4
    New Member
    Join Date
    Aug 2005
    Posts
    4

    Re: Crystal Report 9.0 and VB6

    lol...this may be late but it should work.
    VB Code:
    1. '===================================================================================
    2. 'Create the Crystal Reports Objects
    3. '===================================================================================
    4. If Not IsObject(oApp) Then
    5.     Set oApp = CreateObject("CrystalRuntime.Application")
    6. End If
    7.  
    8. ' CREATE THE REPORT OBJECT
    9. '
    10. 'The Report object is created by calling the Application object's OpenReport method.
    11.  
    12. Dim Path
    13. Dim reportname
    14.  
    15. Path = "**YOUR PATH**"
    16. reportname = "**YOUR REPORT.rpt**"
    17.  
    18. 'OPEN THE REPORT (but destroy any previous one first)
    19.  
    20. If IsObject(oRpt) Then
    21.     Set oRpt = Nothing
    22. End If
    23.  
    24. Set oRpt = oApp.OpenReport(Path & reportname, 1)
    25.  
    26. oRpt.MorePrintEngineErrorMessages = False
    27. oRpt.EnableParameterPrompting = False
    28.  
    29. 'Now we must tell the report to report off of the data in the recordset:
    30.  
    31. oRpt.DiscardSavedData
    32.  
    33. 'Pass parameters to the report
    34.  
    35. 'set up begin and end date to be the first and last days of the previous week
    36.  
    37. oRpt.ParameterFields(1).AddCurrentValue ***YOUR PARM***
    38.  
    39. Dim dbTable
    40.  
    41. ' login to each of the report's tables
    42. For Each dbTable In oRpt.Database.Tables
    43.     dbTable.SetLogOnInfo "**SERVER Connection**", "***DATABASE***", "**USER**", "**PASSWORD***"
    44. Next
    45.  
    46. oRpt.ReadRecords
    47.  
    48. '====================================================================================
    49. ' Exporting the Crystal Report
    50. '====================================================================================
    51.  
    52. outputPath = "**OUTPUT FILE PATH**"
    53. outputfilename = "**OUTPUT FILE**"
    54.  
    55. Set fso = CreateObject("Scripting.FileSystemObject")
    56.  
    57. 'delete final backup target file if it exists
    58. If fso.FileExists(outputfilename & outputPath) Then
    59.     fso.DeleteFile outputfilename & outputPath
    60. End If
    61.  
    62. ExportType = 31
    63.  
    64. 'These lines collect the values passed from the calling HTML page for the export
    65. 'type and filename
    66.  
    67. 'ExportOptions = oRpt.ExportOptions
    68.  
    69. 'First we create an export options collection which allows us access
    70. 'to the exporting properties of the automation server.
    71.  
    72. oRpt.ExportOptions.DiskFileName = outputPath + CStr(outputfilename)
    73.  
    74. oRpt.ExportOptions.FormatType = CInt(ExportType)
    75.  
    76. 'This line sets the file type that the report will be exported to. We
    77. 'use the value that we collected from the calling HTML page.
    78.  
    79. oRpt.ExportOptions.DestinationType = 1
    80.  
    81. 'This line sets the destination of the exported file. 1 means that
    82. 'we are writing the file to disk.
    83.  
    84. On Error Resume Next
    85.  
    86. oRpt.Export False
    87.  
    88. If Err.Number <> 0 Then
    89.     'MsgBox  "Error Occurred Exporting Report: " & Err.Description & Err.number
    90.     oRp = Nothing
    91.     oApp = Nothing
    92. Else
    93.         If IsObject(oPageEngine) Then
    94.          Set oPageEngine = Nothing
    95.         End If
    96.     Set oPageEngine = oRpt.PageEngine
    97. End If
    98. End Sub


    Edit: Added [vbcode][/vbcode] tags and indentation for clairty. - Hack
    Last edited by Hack; Sep 9th, 2005 at 02:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width