Results 1 to 6 of 6

Thread: Crystal report names at run time

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    26

    Unhappy Crystal report names at run time

    Hi,
    PLEASE HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    I REALLY NEEEEEDDD THIS... I CAN"T LIVE WITHOUT THIS... MY LIFE AND SANITY DEPEND ON KNOWING HOW TO DO THIS



    I have reports in my vb6 app that are created with crystal reports 8.5.

    I need a way to be able to set report names (like rptReport1, rptReport2... and I don't mean hard code them in...) to a Global variable at run time so that I can then use this variable to set the ReportSource of the viewer to view the report.


    Currently I have the names of reports and their file names in my database table from which I populate my list box. Once the report is clicked on I do the folowing... but there is a problem..

    global Report as Object
    dim rptName

    If Not rst.EOF Then
    rptName = rst("fld_Rpt_File_Name")
    Set Report = rptName
    Report.ParameterFields(1).SetCurrentValue frmProgramsParameters.ProgramID
    Else
    MsgBox "This is invalid Report! It does not exist in the system", vbCritical, "Bad Report!"
    Exit Sub
    End If

    The problem is that I can't Set Report to rptName because it doesn't see it as Object, but it does contain the report name. I tried making Report a different type but... no luck.

    Is there something like ReportFileName property or a general CrystalReport type or Designer type????????????????
    Juls.

    Every dark cloud has a silver lining but hundreds of people get killed by lightning every year while trying to find it...

  2. #2
    Addicted Member
    Join Date
    Jan 2001
    Location
    MPLS
    Posts
    187
    Try using the application object and then open the report.

    Dim myap as Application
    Set Report = myap.OpenReport(rst("fld_Rpt_File_Name"))

    then set your parameters...

  3. #3
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    You should set the report as the appropriate data type.
    Code:
    Global Report As CrystalReport
    
    Set Report = New CrystalReport
    
    '<---Your code goes here--->
    
    Set Report = Nothing
    You should have the references or components loaded to use this object as well. Specifiying it as an Object will do nothing but 'confuse' the application as you're telling the application to set properties that don't exist in the 'Object' variable. This is used for late binding so that you can use Report as any type of Object. I don't suggest using this unless that's your goal. If all you want the report to be is a crystal report, then declare it as a crystal report (without the New keyword) and set it when you need it and set it to nothing when you do not.
    -Excalibur

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    26
    I am still getting the same error that Object Variable or With block is not set. and it points to the

    Set Report = myap.OpenReport(rst("fld_Rpt_File_Name"))


    ?????? ideas???
    Juls.

    Every dark cloud has a silver lining but hundreds of people get killed by lightning every year while trying to find it...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    26
    Originally posted by ExcalibursZone
    You should set the report as the appropriate data type.
    Code:
    Global Report As CrystalReport
    
    Set Report = New CrystalReport
    
    '<---Your code goes here--->
    
    Set Report = Nothing
    You should have the references or components loaded to use this object as well. Specifiying it as an Object will do nothing but 'confuse' the application as you're telling the application to set properties that don't exist in the 'Object' variable. This is used for late binding so that you can use Report as any type of Object. I don't suggest using this unless that's your goal. If all you want the report to be is a crystal report, then declare it as a crystal report (without the New keyword) and set it when you need it and set it to nothing when you do not.

    I think that is my problem.. What reference or components do I need to be active in my project in order to have CrystalReport recognized as a valid type? right now it doesn't recognize it...
    Also, if I do this

    Global Report As CrystalReport

    will I be able to then do this:

    rptName = rst("fld_Name")
    Set Report = rptName

    ????

    The reason I am asking is.... will I still have problem because it would think that rptName is a string and not a CrystalReport, or would it recognize it as CR??

    Thanks for the help.
    Juls.

    Every dark cloud has a silver lining but hundreds of people get killed by lightning every year while trying to find it...

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    1) Add the Crystal Report (and possibly the Crystal Report Viewer) controls. (CRYSTL32.OCX & CRVIEWER.DLL).

    2) Add the Crystal Report control (looks like a small frame with 6 blocks towards the top.) to your form.

    3) You can then reference it thusly:
    Code:
    Private Sub cmdPrint_Click()
        PrintReport Report(Mid(ListView1.SelectedItem.Key, InStrRev(ListView1.SelectedItem.Key, Chr(4)) + 1))
    End Sub
    
    Private Sub PrintReport(theReport As tmpReport)
        scrReport.ReportFileName = theReport.Path
        scrReport.Connect = "DSN=" & ODBCDSN & ";UID=" & ODBCUID & ";pwd=" & ODBCPWD & ";"
        If theReport.RECSelect <> "" Then
            scrReport.ReplaceSelectionFormula GetFile(RecSelectDir, theReport.RECSelect)
            Else
            scrReport.ReplaceSelectionFormula scrReport.FetchSelectionFormula
        End If
        If theReport.GRPSelect <> "" Then scrReport.GroupSelectionFormula = _
            GetFile(GrpSelectDir, theReport.GRPSelect)
        scrReport.Destination = PrintTo
        On Error Resume Next
        scrReport.PrintReport
        If scrReport.LastErrorNumber > 0 Then MsgBox scrReport.LastErrorNumber & ", " & _
            scrReport.LastErrorString, vbExclamation, "Report Error!"
    End Sub
    Now a few things to note: I created a public type called Report that contains the filepath and everything (just replace that stuff with your code to obtain the filepath). I also store my record select formulae and group select formulae on disk as separate files. You can also replace this. I added the ability to change the ODBC source because of too many pains in the neck settings but pretty much, the above is what you'll need to do to get your crystal report to print using the Crystal Report Control.
    -Excalibur

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