Results 1 to 7 of 7

Thread: Crystal to show recordset

  1. #1

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Question Crystal to show recordset

    Hi, there

    let's say i have created some recordset,
    and i want to pass a parameter value to existing Crystal Report file.
    like this ....

    CRReport.Parameterfields.getitembyneame("test").addcurrentvalues "Test"

    it works fine ...
    but how can i give a parameter value as a recordset like this?

    Fields1 Fields2
    000001 AAAA
    000002 BBBB
    000003 CCC

    or some thing like this ....
    do while not rs.eof
    crreport.parameterfields.getitembyname("test").addcurrentvalues rs.fields!X
    rs.mmovnext
    loop

    Thanks for all help

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

    Re: Crystal to show recordset

    If you are just trying to pass a pre-created CR parameter...
    Code:
    Dim crxApp As CRAXDRT.Application
    Dim oReport As CRAXDRT.Report
    
    Set crxApp = New CRAXDRT.Application
    Set oReport = crxApp.OpenReport(App.Path & "\MyReport", 1)
    oReport.ParameterFields.Item(1).ClearCurrentValueAndRange
    oReport.ParameterFields.Item(1).AddCurrentValue CStr(oRs!Name)
    But it looks like you are trying to pass a recordset to a report? This will do it.
    Code:
    Option Explicit
    'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
    'Add reference to Crystal Reports Viewer Control
    'Add reference to Microsoft ActiveX Data Objects 2.x Library
    'oCnn = current open ADO connection object
    Private Sub Command1_Click()
    
    Dim oApp As CRAXDRT.Application
    Dim oReport As CRAXDRT.Report
    Dim oRs As ADODB.Recordset
    Dim sSQL As String
    
    sSQL = "SELECT * FROM Table1"
    Set oRs = New ADODB.Recordset
    Set oRs = oCnn.Execute(sSQL)
    Set oApp = New CRAXDRT.Application
    Set oReport = oApp.OpenReport(App.Path & "\MyReport.rpt", 1)
    oReport.Database.SetDataSource oRs, 3, 1
    crvMyCRViewer.ReportSource = oReport
    crvMyCRViewer.ViewReport
    
    End Sub
    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 naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Crystal to show recordset

    Thanks RobDog888.
    Is this will automatically assign a fields in Crystal report?

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

    Re: Crystal to show recordset

    No, this will populate your already made report (bound/unbound fields). Say your
    report has a Product Name textbox that is bound to a table's field Product_Name.
    In you code that creates and populates the recordset, you select the same field
    Product_Name and it will populate that control. The beuty of it is that your report
    does not have to be connected to the database because the recordset is actually
    the database.
    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
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Crystal to show recordset

    Thanks a lot RobDog888

  6. #6
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: Crystal to show recordset

    Hi,
    i am new to crystal reports. and this thread helps me lot.
    i want to pass a value as a parameter to crystal report which is selected in my vb application combo box.can i do this.If so please tell me.
    i was created one crystal report with parameter StaffID.
    which is a field in StaffDetails table. i want to pass the parameter StaffID from my vb application without prompting.
    thanks a lot
    wizkid

    my code is :

    Private Sub ViewReport_Click()
    'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
    'Add reference to Crystal Reports Viewer Control
    'Add reference to Microsoft ActiveX Data Objects 2.x Library
    'oCnn = current open ADO connection object


    Dim oApp As CRAXDRT.Application
    Dim oReport As CRAXDRT.Report
    Dim oRs As ADODB.Recordset
    Dim sSQL As String



    sSQL = "SELECT * FROM StaffDetails"
    Set oRs = New ADODB.Recordset
    Set oRs = db_conn.Execute(sSQL)
    Set oApp = New CRAXDRT.Application
    Set oReport = oApp.OpenReport(App.Path & "\MyReport.rpt")
    oReport.Database.SetDataSource oRs, 3, 1
    crvMyCRViewer.ReportSource = oReport
    crvMyCRViewer.ViewReport

    Dim StaffID As CRAXDRT.ParameterFieldDefinitions
    Dim cpar As CRAXDRT.ParameterFieldDefinition
    oReport.EnableParameterPrompting = False

    oReport.ParameterFields.GetItemByName("StaffID").AddCurrentValue "combo1.text"



    End Sub


    but it is giving some error message Invalid name.

  7. #7
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: Crystal to show recordset

    Hi RobDog888,
    please help me!!!
    your code is working fine.
    but my problem is..
    i am not getting the select * from table query values on table
    i was already created the report newreport.rpt.it is a blank report.
    and i want the query result when i press command9 button.
    nearly from 3 weeks i working on this report
    please give me some solution

    Private Sub Command9_Click()
    Dim oreport As CRAXDRT.report
    Dim oapp As CRAXDRT.Application
    Dim oRs As Recordset
    Dim sSQL As String

    Set oRs = New Recordset
    Set oRs = db_conn.Execute("SELECT * FROM table")
    Set oapp = New CRAXDRT.Application
    Set oreport = oapp.OpenReport(App.Path & "\newreport.rpt", 1)

    oreport.Database.SetDataSource oRs, 3, 1

    CRViewer91.ReportSource = oreport
    CRViewer91.ViewReport
    End sub

    thank u

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