Results 1 to 17 of 17

Thread: Invoking Crystal From VB How?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Invoking Crystal From VB How?

    Thanks in advance to all!

    Would appreciate a quick response...

    Thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Add these references to to your project.
    "Crystal Reports x.x ActiveX Designer Runtime Library"
    "Crystal Data Object"
    "Crystal Reports Expert"
    "Crystal Reports x.x Library"
    Then something like this to open the report and export the report as a .pdf file.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Function SendReport(ByVal sWhere As String)
    4.  
    5.     Dim oReport As CRAXDRT.Report
    6.     Dim crxApplication As New CRAXDRT.Application
    7.     Dim crxExportOptions As CRAXDRT.ExportOptions
    8.  
    9.     Set crxApplication = New CRAXDRT.Application
    10.     Set oReport = crxApplication.OpenReport(App.Path & "\Report.rpt", 1)
    11.     oReport.RecordSelectionFormula = sWhere
    12.     Set crxExportOptions = oReport.ExportOptions
    13.     crxExportOptions.DestinationType = crEDTDiskFile
    14.     crxExportOptions.DiskFileName = App.Path & "Report " & Format(Now, "YYYY-MM-DD") & ".pdf"
    15.     crxExportOptions.FormatType = crEFTPortableDocFormat
    16.     crxExportOptions.PDFFirstPageNumber = 1
    17.     crxExportOptions.PDFLastPageNumber = 1
    18.     crxExportOptions.PDFExportAllPages = True
    19.    
    20.     oReport.Export False
    21.  
    22.     'Terminate Cleanly
    23.     Set oReport = Nothing
    24.     Set crxApplication = Nothing
    25.     Set crxExportOptions = Nothing
    26.  
    27. End Function
    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
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Mille merci(s)

    Thanks a mil...
    The .pdf is created in the path of the application...
    which I later opened

    Any way to open on the fly?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I suppose your could after the termination code use the file name
    and shell Acrobat Reader with the file name as a parameter.
    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ..Again

    Thanks

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ...me again>

    I am shelling acrobar reader...
    I don't see the .pdf on the screen...
    I have to go to the taskbar ang maximize... it to see it at all

    Any ideas? Can't I just pop it on top?

    Thanks in advance...

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    To shell Acrobat or program associated with the .pdf extension use...
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    4. ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
    5. ByVal nShowCmd As Long) As Long
    6.  
    7. Const SW_SHOWNORMAL As Long = 1
    8. Const SW_SHOWMAXIMIZED As Long = 3
    9. Const SW_SHOWMINIMIZED As Long = 2
    10.  
    11. Private Sub cmdShellPDF_Click()
    12.     'WITH THE YOU CAN SET THE WORKING DIRECTORY TOO!
    13.     ShellExecute Me.hwnd, vbNullString, "D:\Test.pdf", vbNullString, "D:\", SW_SHOWMAXIMIZED
    14. End Sub
    Let me know if this was what you were describing.
    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

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Rob...

    Thanks much....

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Your welcome.
    Glad to help.
    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

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    one q

    I have a table with two fields ActivityDate and Event
    How do I pass a parameter to the crystal report so that
    it displays events not greater than x number of days old only..

    Currently, the report is showing all events

    Thanks

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Use the parameterfields of the oReport object. You need to clear
    each parameter before you set a value to it, every time.
    Code:
    oReport.ParameterFields.Item(1).ClearCurrentValueAndRange
    oReport.ParameterFields.Item(1).AddCurrentValue dActivityDate
    oReport.ParameterFields.Item(2).ClearCurrentValueAndRange
    oReport.ParameterFields.Item(2).AddCurrentValue sEvent
    HTH
    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

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Pls

    Bear with me

    The report has subreports and is created external to VB
    and I am exporting it into .pdf as u showed me and kick acrobat
    to display it... Now, it is one of the subreborts for which I need
    a parameter field... So the user could be prompted on the fly (if possible) to enter something and corresponding data would be displayed..

    Do we add a parameter field to the individual report before
    entering as a subreport...

    I guess I am asking how does it all tie...together ?

    Currently, my main report displays data for all organizations grouping them by OrgID then the subreport displays data just for the orgID being displayed.. But it's displaying all the activities for it since the beginning of time for the ORg.. What I'd like to do is to create a field that the client could enter a number like 30 enter and only last 30 days activity (for example) would be displayed..

    I am probably verbose... But that happens when one has little time to do something with a new tool..

    Thanks again

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Hi

    How does one refresh the report data frm within VB?

    Thanks

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Since the report is exported out as a pdf file, the report can not
    be refreshed unless you re-export the report.
    You may want to look at using the Crystal Report Viewer control
    in VB to allow you to view/export the report in real time.
    Although if you are distributing the program ther may be licensing issues.


    As far as the previous post, you need to create a parameter at
    the main report level. Then link the parameter to the subreport
    by reimporting the sub report. This will allow you to pass a
    parameter to the report which will inturn go to the sub report.


    HTH
    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

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ...As

    always...

    Thanks..

    For the previous post
    Even ReExporting does not seem to do it.. I'll check again...

    As for the prior post..

    I have decided to create stored procedures which accept parameters that populate a table with the data that I need and the report or subreport would then extract from that table..

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ok

    Actually, the export would work if one opts to not save the data with the report....

    Thanks

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    In Crystal Reports, when you created the report, there is a
    setting under File > Options > Reporting tab... called "Save data
    withreport" checkbox. Uncheck it and resave your report. Also,
    since you have a subreport, under the New Report tab there is
    another checkbox to "Reimport subreport subreports when
    opening reports". I'm not too sure if that is only for the
    development enviroment or if it could affect your results.


    HTH
    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

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