Results 1 to 4 of 4

Thread: how to call report from crystal report with out using Crystal report viewer in vb.net

  1. #1

    Thread Starter
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    Resolved how to call report from crystal report with out using Crystal report viewer in vb.net

    Hi all!

    I have a report in the crystal report tool not in the vb.net.
    and i save it and a report file.but i do not know how to call this report file for printpreview/print by vb.net not use .net crystal report viewer tool?
    did you have some solution and the sample code for this problem?

    i hope this problem will solve.

    best regards,
    thirith.
    Last edited by thirith; Feb 17th, 2005 at 12:25 AM.

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

    Re: how to call report from crystal report with out using Crystal report viewer in vb.net

    I just wrote this example for someone today. It is in VB6 syntax but it should help you. The database
    backend s for SQL Server but its similar for Access.

    VB Code:
    1. Option Explicit
    2. 'Add references to:
    3. 'Crystal Reports Viewer Control
    4. 'Crystal Reports 8.5 ActiveX Designer Run Time Library
    5. 'Crystal Reports 8.5 Library
    6. 'Microsoft ActiveX Data Objects 2.x Library
    7. Private moApp As CRAXDRT.Application
    8. Private moReport As CRAXDRT.Report
    9. Private moCnn As ADODB.Connection
    10. Private moRs As ADODB.Recordset
    11.  
    12. Private Sub Command1_Click()
    13.     Set moRs = New ADODB.Recordset
    14.     moRs.Open sSQL, moCnn, adOpenKeyset, adLockOptimistic, adCmdText
    15.     If moRs.BOF = True And moRs.EOF = True Then
    16.         MsgBox "No Record(s) returned!", vbOKOnly + vbExclamation
    17.     Else
    18.         Dim sUserName As String
    19.         Dim sUserName As String
    20.         Dim sUserPwd As String
    21.         Dim sServer As String
    22.         Dim sDatabase As String
    23.         Dim sPara1 As String
    24.         Dim sPara2 As String
    25.         Set moReport = New CRAXDRT.Report
    26.         Set moReport = moApp.OpenReport(App.Path & "\MyReport.rpt", 1)
    27.         sUserName = "MyUserName"
    28.         sUserPwd = "mypassword"
    29.         sServer = "ServerName"
    30.         sDatabase = "DatabaseName"
    31.         sDriver = "P2SSQL.DLL"
    32.         moApp.LogOnServer "P2SSQL.DLL", sServer, sDatabase, sUserName, sUserPwd
    33.         moReport.Database.Tables(1).SetLogOnInfo sServer, sDatabase, sUserName, sUserPwd
    34.         moReport.ParameterFields.Item(1).ClearCurrentValueAndRange
    35.         moReport.ParameterFields.Item(1).AddCurrentValue sPara1
    36.         moReport.ParameterFields.Item(2).ClearCurrentValueAndRange
    37.         moReport.ParameterFields.Item(2).AddCurrentValue sPara2
    38.         moReport.Database.SetDataSource moRs, 3, 1
    39.         CRViewer1.ReportSource = moReport
    40.         CRViewer1.ViewReport
    41.         CRViewer1.ShowFirstPage
    42.     End If
    43. End Sub
    44.  
    45. Private Sub Form_Load()
    46.     Dim sSQL As String
    47.     Dim sDB As String
    48.     Dim sServer As String
    49.     sSQL = "SELECT * FROM Table1 WHERE Something = SomethingElse;"
    50.     sDB = "MyDatabase"
    51.     sServer = "MyServer"
    52.     Set moCnn = New ADODB.Connection
    53.     moCnn.ConnectionString = "provider=sqloledb;data source=" & sServer & ";initial catalog=" & sDB & ";integrated security=sspi;"
    54.     moCnn.Open
    55. End Sub
    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

  3. #3

    Thread Starter
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    Resolved Re: how to call report from crystal report with out using Crystal report viewer in vb.net

    Thanks RobDog888
    the code that post is solved my problem by using this code.
    Thirith.

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

    Re: how to call report from crystal report with out using Crystal report viewer in vb.net

    Glad to have helped , but I knowI posted an ex using the viewer control, but you
    stated that you didnt want to use it. Just a little thats all.
    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