Results 1 to 12 of 12

Thread: calling report

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    calling report

    Hi,

    Please guide us how to call crystal report into visual basic.


    ASM

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

    Re: calling report

    I have a short example in my signature - "VB6/Crystal Report Ex."
    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Re: calling report

    Hi
    I have gone through your example coding... and try accordingly
    but i can not find crystal reports reference in vb6 project-Reference..
    please guide me...

    ASM

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Kolkata, India
    Posts
    290

    Re: calling report

    Hi

    I have gone trhough your example but I can not get project-reference
    for crystal reports you have mention...


    Thanks

  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    36

    Re: calling report

    Hi ASM,
    Hope you are not frustrated by now!
    I went thru the same questions that you have.
    Here is my sample code:

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3. Dim path As String
    4. Dim reportname As String
    5.  
    6. path = "ReportPath\"
    7. reportname = "ReportName.rpt"
    8.  
    9. Dim oApp As CRAXDRT.Application
    10. Dim oReport As CRAXDRT.Report
    11. Dim ors As dao.Recordset
    12. Dim ssql As String
    13.  
    14. Set oApp = New CRAXDRT.Application
    15. Set oReport = oApp.OpenReport(path & reportname)
    16. CRViewer91.ReportSource = oReport
    17. CRViewer91.ViewReport
    18.  
    19. Screen.MousePointer = vbDefault
    20.  
    21. End Sub

    Couple things:
    Make sure you have Crystal Viewer installed. I think there is one common viewer for any kind of reports.
    Once you do that, include 'Crystal Viewer 9.0 ActiveX designers....' reference in to your vb project.

    After above two steps, you will have access to CRAXDRT library.

    Thanks RobDog for the code.

    Ankeet.

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

    Re: calling report

    Quote Originally Posted by asm
    Hi

    I have gone trhough your example but I can not get project-reference
    for crystal reports you have mention...


    Thanks
    The references are available if you have Crystal Reports installed. Do you have a copy of the program? The references might vary a little on newer versions of CR but should still be visible.

    The CR Viewer control is only available if you have CR installeed on your system.



    Your Welcome, ankeet1. Glad it has helped as it doesnt get much notice.

    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

  7. #7
    Member
    Join Date
    Jul 2005
    Posts
    36

    Re: calling report

    RobDog,
    Your code works well, I can open report i can even execute this line
    VB Code:
    1. oReport.Database.SetDataSource oRs, 3, 1
    but, when the report opens, it still prompts me for parameters. How do i stop this?!!

    Ankeet

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

    Re: calling report

    That is caused by the report file itself. Open it up on the Crystal Report designer, and remove the part that calls for parameters.

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

    Re: calling report

    Ok, in your report in Crystal Reports you must have created some parameters? You need to pass these parameters before you open the report using the Parameters collection.
    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

  10. #10
    Member
    Join Date
    Jul 2005
    Posts
    36

    Re: calling report

    Yes,
    when i created the reports, I did have a stored proc set as data source and that stored proc expects parameters.

    There is no place else in the report which uses any of these parameters. I do have calculated fields (formulas) but they are calculated based on grouping and values from the stored proc.

    Also,
    robDog, can you point me to some place which demonstrates using the Parameters collection.
    I followed one of the posts and tried to pass 'discrete' parameters in following way:
    VB Code:
    1. crParameterFieldDefs = oReport.DataDefinition.ParameterFields
    But, when i type 'oReport.' there is no drop down list which means, i might need to include some more references. Which ones?


    Your help is GREATLY appreciated!
    Ankeet

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

    Re: calling report

    oReport is my Report object. There should be a Parameters collection right off of the Report object. DataDefinition is for using ttx files with CR.
    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

  12. #12
    Member
    Join Date
    Jul 2005
    Posts
    36

    Re: calling report

    Guys once again!
    A'ight, i fixed the previous issue of passing parameters. Now it does not ask me for param values. Below is the code.

    Also, as you can see from the code, i use a WHILE loop to open multiple reports. Thats where the problem is - how do i open multiple reports (tabbed browsing)?

    VB Code:
    1. While Not de.rsdbo_spMES_GetSelectedReports.EOF
    2.        
    3.         Set oApp = New CRAXDRT.Application
    4.         Set oReport = oApp.OpenReport(App.Path & "\Reports\" & _
    5.                     de.rsdbo_spMES_GetSelectedReports.Fields("CSName").Value)
    6.        
    7.         ' CALL the modReportViewer.
    8.         ' Pass the report name, based on which the modReportViewer
    9.         ' will call appropriate report wrappers and return a
    10.         ' record set.
    11.         oReport.DiscardSavedData
    12.         'oReport.Database.SetDataSource ReportFetcher(de.rsdbo_spMES_GetSelectedReports.Fields("CSName").Value), 3, 1
    13.        
    14.         ' get the count of parameter fields in the current report
    15.         ParamCount = oReport.ParameterFields.Count
    16.        
    17.         ' loop for number times = param count.
    18.         ' Also make sure EVERY STORED PROC SHOULD USE SAME NAME FOR PARAMETERS.
    19.         ' ANY NEW PARAMETER SHOULD BE ADDED TO THE CASE STATEMENT.
    20.         For i = 1 To ParamCount
    21.             Select Case LCase(oReport.ParameterFields(i).ParameterFieldName)
    22.                 Case LCase("@CurrentRepCompany")
    23.                     oReport.ParameterFields(i).AddCurrentValue (gCompany)
    24.                 Case LCase("@CurrentRepPlantID")
    25.                     oReport.ParameterFields(i).AddCurrentValue (gPlantID)
    26.                 Case LCase("@CurrentRepDepartmentID")
    27.                     oReport.ParameterFields(i).AddCurrentValue (gDepartmentID)
    28.                 Case LCase("@CurrentRepLineID")
    29.                     oReport.ParameterFields(i).AddCurrentValue (gLineID)
    30.                 Case LCase("@CurrentRepItemID")
    31.                     oReport.ParameterFields(i).AddCurrentValue (gItemID)
    32.                 Case LCase("@CurrentRepProdDate")
    33.                     oReport.ParameterFields(i).AddCurrentValue (CDate(gBeginDate & " 00:00"))
    34.                 Case LCase("@CurrentRepEndDate")
    35.                     oReport.ParameterFields(i).AddCurrentValue (CDate(gEndDate & " 00:00"))
    36.                 Case LCase("@CurrentUser")
    37.                     oReport.ParameterFields(i).AddCurrentValue (gCurrentUserID)
    38.             End Select
    39.         Next i
    40.            
    41.                
    42.        
    43.        
    44.         ' do not let the user refresh the data on the report.
    45.         ' user can close the report and open it again.
    46.         crViewer.EnableRefreshButton = False
    47.        
    48.         ' display tabs.
    49.         crViewer.DisplayTabs = True
    50.         crViewer.TabIndex
    51.        
    52.         crViewer.ReportSource = oReport
    53.         crViewer.ViewReport
    54.        
    55.         Screen.MousePointer = vbDefault
    56.        
    57.         de.rsdbo_spMES_GetSelectedReports.MoveNext
    58.     Wend

    Thanx for your help!
    Ankeet

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