Results 1 to 8 of 8

Thread: Setting Crystal Reports to Data to a Recorset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Sydney Australia
    Posts
    476

    Angry

    Hi team

    I want to dynamically create an RS and then set the Crystal to look at it with "Database.SetDataSource myRS" (I'm Using the Crystal Reports Designer). But it doesn't work. It seems that Crystal is looking for a table rather than an RS. In DAO I could have created a table on the fly, but I can't see how to do that with ADO. Any bright ideas?

  2. #2
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    Here's an example of how I set a recordset to a report. I have a form named frmReport which contains a crystal report viewer control (crvCommon).

    Code:
        Dim rstCurrent As ADODB.Recordset
        Dim strSql As String
        Dim Report1 As rptAdjuster
        
        strSql = "SELECT Adjuster.client_num, TRIM(Adjuster.adj_last)+', '+ TRIM(Adjuster.adj_first) as Name, Company.comp_name, Company.city "
        strSql = strSql & "FROM openclose!company INNER JOIN openclose!adjuster "
        strSql = strSql & "ON Company.comp_id = Adjuster.comp_id ORDER BY name"
        
        Load frmReport
    
        Set rstCurrent = New ADODB.Recordset
        rstCurrent.Open strSql, fCnn1, adOpenForwardOnly, , adCmdText
    
        Set Report1 = New rptAdjuster
    
        Report1.Database.SetDataSource rstCurrent
    
        frmReport.crvCommon.ReportSource = Report1
    
        frmReport.crvCommon.ViewReport
    
        frmReport.crvCommon.Visible = True
    
        frmReport.Show
    Hope this helps.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Sydney Australia
    Posts
    476

    Thanks Derick

    From freewilly re dynamically set CR record source

  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    dcarlson,

    I am having trouble with your code, it complains about the rptAdjuster data type in the line
    Code:
    Dim Report1 As rptAdjuster
    I am using Crystal reports 8, would this have something to do with it, what version are you using.


    Things I do when I am bored: DotNetable

  5. #5
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    rptAdjuster is the name my report. You need to create a report and replace rptAdjuster with the name of your report.

  6. #6
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    rptAdjuster?

    Dcarlson,

    I can't get your code to work either due to the rptAdjuster datatype. How did you reference rptAdjuster? I tried to add a reference to my report, but it didn't work. Please give a little more details.

  7. #7
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274
    You need to create report using the Crystal Report Designer Component within VB. You can do this by clicking on the Project menu and Add Crystal Reports 8. In my case, I named my report rptAdjuster and set an Object variable to that report. Replace rptAdjuster with the name of your report.
    Code:
    Dim Report1 as YourCrystalReport
    If you want examples look under
    C:\Program Files\Seagate Software\Crystal Reports\Samples\Code\Visual Basic

  8. #8
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600
    Derrick,

    Thanks for the follow-up. I guess I'm having a problem because I don't have Crystal Report 8. I only have version 4.6 which shipped with Visual Studio.

    However, I think I can figure out a solution to my problem.

    Thanks again.

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