Results 1 to 4 of 4

Thread: [RESOLVED] Pass Vb global variable to CR

  1. #1
    Member
    Join Date
    Feb 12
    Posts
    51

    Resolved [RESOLVED] Pass Vb global variable to CR

    I have a global variable that I want to use in all my CRs, its set when my main menu opens, works quite well and I have it as a title on all my forms. It is layed out like this. strTitle
    ACME Housing Development
    123 Any street
    Some City, State, Zip
    Phone 555-555-1212, Fax: 555-555-1313
    John Doe Executive Director

    Anyway I want to use that for the title of all my reports but I'm having trouble comprehending how to pass the variable to my report viewer and onto my report.
    I've found a couple examples, and can't seem to get any of them to work.

    If someone has a short example of how to pass the variable that would be great.

    Thanks
    LB

  2. #2
    Frenzied Member
    Join Date
    May 06
    Location
    some place in the cloud
    Posts
    1,622

    Re: Pass Vb global variable to CR

    You didn't say CR version, anyway I'll assume that you are using RDC

    You could do it using formula fields

    In the rpt
    Insert a formula field in the page header section, lets say @Title
    Code:
    Trim("Here goes title")
    In vb6 code
    (You need to reference Crystal ActiveX Report Viewer Library)
    Code:
    Dim MEnt1 As Integer
    Dim CRApplication As New CRAXDRT.Application
    Dim CRReport As New CRAXDRT.Report
    '
    'code goes here
    '
    Set CRReport = CRApplication.OpenReport("MyRpt.rpt", 1)
    '
    '
    '
    For MEnt1 = 1 To CRReport.FormulaFields.Count
        Select Case CRReport.FormulaFields(MEnt1).name
            Case "{@Title}"'this is name of the formula in CR
                      CRReport.FormulaFields(MEnt1).Text = "Trim(" & Chr(39) & "ACME Housing Development." & Chr(39) & ")"
            Case "{@XXX}"
                      CRReport.FormulaFields(MEnt1).Text = "something else"
        End Select
    Next MEnt1
    In vb.net code
    Code:
    'You need to declare variables and CR objects
    For Ment1 = 0 To CRReport.DataDefinition.FormulaFields.Count - 1
        Select Case CRReport.DataDefinition.FormulaFields.Item(CRCount).Name.ToString
            Case "Title" : CRReport.DataDefinition.FormulaFields.Item(MEnt1).Text = "Trim(" & Chr(39) & "ACME Housing Development." & Chr(39) & ")"
            Case "b" : CRReport.DataDefinition.FormulaFields.Item(MEnt1).Text = "any aother value"
        End Select
    Next MEnt1
    This is an example in how to pass a text to a rpt using formula fields
    Last edited by jggtz; Jul 30th, 2012 at 06:33 PM.
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    Frenzied Member
    Join Date
    Sep 05
    Location
    Modesto, Ca.
    Posts
    1,590

    Re: Pass Vb global variable to CR

    Not sure about old versions but CR for 2010 has fields especially for that,
    Dim frm as New frmReports
    Dim rpt As New GroupsByUserId
    rpt.SummaryInfo.ReportTitle = clsCoInfo.CompName & vbNewLine & clsCoInfo.Address1
    rpt.SummaryInfo.ReportComments = "What ever you want to say"
    rpt.SummaryInfo.ReportAuthor = "report author"
    rpt.SetDataSource(yourdatasource)
    frm.CrystalReportViewer1.ReportSource = rpt
    frm.ShowDialog()
    Look in the Field Explored->Special Fields

  4. #4
    Member
    Join Date
    Feb 12
    Posts
    51

    Re: Pass Vb global variable to CR

    Ah that's cool.
    I ended up using this:
    DepositDispositionRpt1.SetParameterValue("ReportHeading", strReportHeading)
    strReportHeading being a global variable in my application

    I'm sure going to give your example a try.

    Thanks
    LB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •