Results 1 to 7 of 7

Thread: Display variable value in Crystal Report Text Box

  1. #1

    Thread Starter
    Addicted Member rpk_20061975's Avatar
    Join Date
    Jun 2001
    Location
    India
    Posts
    234

    Question Display variable value in Crystal Report Text Box

    In my application I have certain calculated values stored in variables. I am using Visual Basic 6 and Crystal Reports 8.5 and my Report has certain Text Boxes where I want to display the calculated values. I don't want to use the Data Fields. I want to do like this:

    Code:
    Dim C as ...CrystalReport1
    Dim var1, var2 As String
    
    Set C = New CrystalReport1
    
    C.txtName.Text = var1
    C.txtNumber.Text = var2
    But the Crystal Report displays an error at lines "C.txtName", saying that it is a Read-Only field.

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    Why not use parameters? such as;

    Set the fields as parameters on your report . Then in your code..

    Report.ParameterFields.Item(1).AddCurrentValue var1
    Report.ParameterFields.Item(2).AddCurrentValue var2

    I am using CR9.5, so the syntax may vary slightly.

  3. #3

    Thread Starter
    Addicted Member rpk_20061975's Avatar
    Join Date
    Jun 2001
    Location
    India
    Posts
    234
    I tried this, and this command style is available in 8.5 also. But as I call the report from VB (runtime), Crystal Report displays a dialog box to enter the parameter value. But I want the variable value to be automatically transferred to the parameters and the report should start printing.

  4. #4
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    It shouldn't ask you for the value if you run it from within your VB app. If you supply the values when you run the report, it works fine (for me). Example:

    Set Report = crxApplication.OpenReport("Z:\DAD\ShipvsProd.rpt", 1)
    For Each crxDatabaseTable In Report.Database.Tables
    crxDatabaseTable.ConnectionProperties("user id") = "sa"
    crxDatabaseTable.ConnectionProperties("Password") = myPasswordTechniSQL
    Next crxDatabaseTable
    Report.SelectPrinter glbPrinterDriver, glbPrinterName, glbPrinterPort
    Report.PaperOrientation = crDefaultPaperOrientation
    Report.ParameterFields.Item(1).AddCurrentValue glbDate
    Report.ParameterFields.Item(2).AddCurrentValue glbDate1
    If glbPrinterDestination = 0 Then
    glbReportForm = "frmProduction"
    CRViewer.Show vbModal
    Else
    Report.PrintOut False
    End If

  5. #5
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423
    Guy,

    If i have created 1 Crystal report, how can i use that report
    using App.Path.

    I mean i want to use that like this REPORT.SOURCE
    (or something i dont know ) = App.Path & "\TEST.RPT"


    Thanks
    The only easy day was yesterday

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    VB Code:
    1. Option Explicit
    2. 'Add reference to -
    3. 'Crystal Data Object
    4. 'Crystal Reports x.x Library
    5. 'Crystal Reports x.x ActiveX Designer Runtime Library
    6. Private oReport As CRAXDRT.Report
    7. Private crxApp As CRAXDRT.Application
    8.  
    9. Private Sub Command1_Click()
    10.  
    11.     Set crxApp = New CRAXDRT.Application
    12.     Set oReport = New CRAXDRT.Report
    13.  
    14.     Set moReport = crxApp.OpenReport(App.Path & "\TEST.rpt", 1)
    15.     '...
    16.     '...
    17.     '...
    18.  
    19. 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

  7. #7
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423
    Thanks a lot man
    The only easy day was yesterday

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