Results 1 to 12 of 12

Thread: [RESOLVED] recordset result on crystal

  1. #1

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Resolved [RESOLVED] recordset result on crystal

    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 crystal.
    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

    VB Code:
    1. Private Sub Command9_Click()
    2.     Dim oreport As CRAXDRT.report
    3.     Dim oapp As CRAXDRT.Application
    4.     Dim oRs As Recordset
    5.     Dim sSQL As String
    6.  
    7.     Set oRs = New Recordset
    8.     Set oRs = db_conn.Execute("SELECT * FROM table")
    9.     Set oapp = New CRAXDRT.Application
    10.     Set oreport = oapp.OpenReport(App.Path & "\newreport.rpt", 1)
    11.  
    12.     oreport.Database.SetDataSource oRs, 3, 1
    13.  
    14.     CRViewer91.ReportSource = oreport
    15.     CRViewer91.ViewReport
    16. End sub

    thank u
    Last edited by RobDog888; Jan 30th, 2006 at 02:06 PM. Reason: Added [vbcode] tags

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

    Re: recordset result on crystal

    Ok, you say you created the report in CR but did you use the same fields from Table when you bound the textboxes to the fields?
    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 wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: recordset result on crystal

    hi robdog888,
    thanks for your reply.
    really i don't know how to get the values to report.
    i created a blankreport just adding one table to data expert in crystal report.
    i haven't added any fields to report .it is completely blank.
    could you please advice me how to create the report,and get the values from sql query to crystal report.
    thanks
    wizkid

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

    Re: recordset result on crystal

    Moved to reporting section

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

    Re: recordset result on crystal

    Oh, thats why. You need to open the field explorer and drag the field you want on your report to the actual report. If you dont add any fields to the report page then your report wil be blank.
    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

  6. #6

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: recordset result on crystal

    Hi, thanks for ur suggestion but the thing is i am not asking for the crystal report designing, i know crystal reports designing but what i wanted to do is, i wanted to run some queries and get those results on the report, i am doing some calculations for the style_code and all, so we need to show them calculations and figures on the report.

    i have one more doubt,on ur code you have given as

    VB Code:
    1. Set oRs = New Recordset
    2. Set oRs = db_conn.Execute("SELECT * FROM table")
    3. Set oapp = New CRAXDRT.Application
    4. Set oreport = oapp.OpenReport(App.Path & "\newreport.rpt", 1)
    5.  
    6. [COLOR=RoyalBlue]oreport.Database.SetDataSource oRs, 3, 1[/COLOR]
    7.  
    8. CRViewer91.ReportSource = oreport
    9. CRViewer91.ViewReport
    10. End sub

    i wanted to know, what will the blue colour line code do there ?

    thank you,
    wizkid.

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

    Re: recordset result on crystal

    It binds the ADO recordset resultset to the report but it will only show data if you have the corresponding fields bound to controls on the report. You can use a generic sql statement that brings in the desired fields in CR. Then all you need to do is modify the sql query to perform any calculations, 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

  8. #8

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: recordset result on crystal

    Hi RobDog888,
    thanks for your reply.
    ok fine.
    for example i want to get the result..like select * from employee where staffid=123 into the report.
    1.to get the result how should i design the report and
    2.which code should i write in vb
    please give me steps
    thanks a lot
    wizkid

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

    Re: recordset result on crystal

    Ok, in CR set your database location and create an ADO connection to it. Then select the Employees table as your source table. Once you have that part you can add the fields to your details section. Make sure you have "Save data with report" unchecked in the report properties.

    next in VB do like my code example but the ADO connectionstring will be pointing to the database location. It should either be relative if its a local db or an UNC path to the server\share it resides. Then when you .Open your recordset, pass the new sql statement like you posted. The the rest is the same.
    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
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: recordset result on crystal

    Hi RobDog888,
    Thanks a lot for your suggestions.

    i followed all your instructions.

    VB Code:
    1. Dim db_conn As New ADODB.Connection
    2. Dim rs As ADODB.Recordset
    3. Private Sub Form_Load()
    4.    
    5.     Dim CRReport As CRAXDRT.Report
    6.     Dim CRApp As New CRAXDRT.Application
    7.    
    8.     'Open the Crystal Report
    9.     Set CRReport = CRApp.OpenReport("C:\Program Files\Microsoft Visual Studio\VB98\newreport\Report2.rpt")
    10.     Set rs = New ADODB.Recordset
    11.     db_conn.Open "Driver={Microsoft ODBC for Oracle};" & _
    12.     "Server=TEST;" & _
    13.     "Uid=scott;" & _
    14.     "Pwd=tiger"
    15.     Dim sqlq As String
    16.     sqlq = "Select * from Employee where EmpID = 1"
    17.     With CRReport
    18.         .Database.Tables(1).Location = App.Path & "\MagData"
    19.         rs.Open sqlq, db_conn, adOpenStatic, adLockReadOnly
    20.        
    21.   End With
    22.        
    23. End Sub

    MagData is our oracle database
    rs.Open sqlq, db_conn, adOpenStatic, adLockReadOnly -------after this statement how can i proceed? i want to show the report in CrystalActiveXReportViewer
    thank you
    wizkid

  11. #11

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: recordset result on crystal

    Hi RobDog888,
    Thank you very much for your help.
    thanks a lot.
    i got it.
    it is working fine

    VB Code:
    1. Dim db_conn As New ADODB.Connection
    2. Dim rs As ADODB.Recordset
    3. Private Sub Form_Load()
    4.    
    5.     Dim CRReport As CRAXDRT.Report
    6.     Dim CRApp As New CRAXDRT.Application
    7.    
    8.     'Open the Crystal Report
    9.     Set CRReport = CRApp.OpenReport("C:\Program Files\Microsoft Visual Studio\VB98\newreport\Report2.rpt")
    10.     Set rs = New ADODB.Recordset
    11.     db_conn.Open "Driver={Microsoft ODBC for Oracle};" & _
    12.     "Server=Test;" & _
    13.     "Uid=Scott;" & _
    14.     "Pwd=tiger"
    15.     Dim sqlq As String
    16.     sqlq = "Select empid from employee where empid like 'M4%'"
    17.     With CRReport
    18.         'Set the Access database path
    19.         .Database.Tables(1).Location = App.Path & "\MaData"
    20.         rs.Open sqlq, db_conn, adOpenStatic, adLockReadOnly
    21.          .Database.SetDataSource rs, 3, 1
    22.         CrystalActiveXReportViewer1.ReportSource = CRReport
    23.        CrystalActiveXReportViewer1.ViewReport
    24.   End With
    25.        
    26. End Sub

    if i get any problem i will ask you.

    once again thank you
    wizkid
    Last edited by wizkid; Jan 31st, 2006 at 04:41 AM.

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

    Re: recordset result on crystal

    Glad its finally working for you now.

    Ps, dont forget to 'Resolve' your thread so others will know its solved.
    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