Results 1 to 12 of 12

Thread: Crystal Report 9.0 and VB6

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    36

    Crystal Report 9.0 and VB6

    Hi All,
    I know this question has been posted many times. But I could not get a specific answer for my confussion.

    I am creating reports using Crystal. All is good until the stored proc (SQL 2000) requires a parameter.

    How do I write a generic function in VB6 that will open the selected report and pass the required parameters. Would I still have to go through the ado connection stuff etc.?

    RobbDog, I did see the link in your signature, but that does not answer my above question.

    Also, is there any tool that will let me convert my Access reports to CR9 reports?

    Thanx all for your help.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Crystal Report 9.0 and VB6

    Quote Originally Posted by ankeet1
    How do I write a generic function in VB6 that will open the selected report and pass the required parameters. Would I still have to go through the ado connection stuff etc.?
    Rather than messing about with CR parameters, I just pass it the result of a recordset that I've created based on an SQL query.
    Quote Originally Posted by ankeet1
    Also, is there any tool that will let me convert my Access reports to CR9 reports?
    No, not that I know of. Those reports will all have to be converted manually.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Crystal Report 9.0 and VB6

    If you do use a generic function to open your report you will have to use the Parameters collection to add each parameter to the collection. Then set the DataSource and open. You will have to keep track of which report requires which parameters, etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #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.

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    36

    Re: Crystal Report 9.0 and VB6

    Circusfit,
    I just looked up your reply. I was caught up in a different project and now i am back to this project.

    I will definitely give it a shot. THe way you have written the code, i am almost sure that this should be the solution to my question!

    Thanks a lot.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Crystal Report 9.0 and VB6

    One thing. In the Err.Number section, you need to use Set to destroy the objects.
    VB Code:
    1. oRp = Nothing
    2.     oApp = Nothing
    3. 'needs to be
    4. Set  oRp = Nothing
    5. Set  oApp = Nothing

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    36

    Re: Crystal Report 9.0 and VB6

    VB Code:
    1. Set oApp = CreateObject("CrystalRuntime.Application")

    I get the following error at the above line:
    Run-time Error 439.
    ActiveX Component can't create object.


    Probably, the app cannot find CrystalRuntime. Shouldn't it have been installed at the time of installation? We also have Crystal Viewer set up. Also, would this code NOT work with CR 11? I know my message title mentions CR 9, but last friday, we upgraded to CR11 (well, because of some tech issues, they will be down grading back to CR 9 next week, until they can find some permenant solution).

    Thanks for the help!

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Crystal Report 9.0 and VB6

    Crystal runtimes may or may not be automatically added to your setup and installation package. It depends on which one you are using. The P&DW does not.

    Repackage your project and make sure those runtimes are included.

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    36

    Re: Crystal Report 9.0 and VB6

    I am actually getting the error when I am compiling the project. What reference file(s) need to be included in vb6?
    Excuse me for being a pain, but some how the code is just not work successfully.

    Thank You.

  10. #10
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Crystal Report 9.0 and VB6

    I think you need : craxdrt.dll


    [EDIT] OOps.. lol I was searching, then posted an answer.. nice! Pay attention! [/EDIT]
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  11. #11
    New Member
    Join Date
    Oct 2005
    Posts
    15

    Re: Crystal Report 9.0 and VB6

    When you install the crystal, it autometically adds reference in VB. So it you go to the reference list, you should find one for Crystal.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Crystal Report 9.0 and VB6

    Quote Originally Posted by tansarbh
    When you install the crystal, it autometically adds reference in VB. So it you go to the reference list, you should find one for Crystal.
    True, and you should also find the components for Crystal Reports under the Components section on the VB IDE.

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