Results 1 to 9 of 9

Thread: Controlling report results thru VB.Net???

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Controlling report results thru VB.Net???

    Does anyone have a good example of using CR in .Net? I'm new to .Net in general and this version of CR. I was never really great at writing CR reports. I'm curious as to how much of the report can be controlled thru VB code.

    Thanks,
    Blake

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Controlling report results thru VB.Net???

    VB Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Imports CrystalDecisions.CrystalReports.Engine
    5. Imports CrystalDecisions.Shared
    6.  
    7. Dim crDatabase As Database
    8. Dim crTables As Tables
    9. Dim crTable As Table
    10. Dim crTableLogOnInfo As TableLogOnInfo
    11. Dim crConnectionInfo As ConnectionInfo
    12.  
    13.  
    14. Me.CrystalReportViewer1.Width = Me.Width - 30
    15. Me.CrystalReportViewer1.Height = Me.Height - 50
    16.  
    17.  
    18. Dim crReportDocument As New CrystalReport1
    19. crConnectionInfo = New ConnectionInfo
    20. With crConnectionInfo
    21.     .ServerName = "Dinefer"
    22.     .DatabaseName = "Dinefer"
    23.     .UserID = "Utilizador"
    24.     .Password = "ab,cdef123!"
    25. End With
    26. crDatabase = crReportDocument.Database
    27. crTables = crDatabase.Tables
    28. For Each crTable In crTables
    29.     crTableLogOnInfo = crTable.LogOnInfo
    30.     crTableLogOnInfo.ConnectionInfo = crConnectionInfo
    31.     crTable.ApplyLogOnInfo(crTableLogOnInfo)
    32. Next
    33.  
    34. formula = "{auxprintcorpoenc.login}='" & Utilizador.Login & "'"
    35. crReportDocument.RecordSelectionFormula = formula
    36. crReportDocument.PrintOptions.PaperOrientation = PaperOrientation.Landscape
    37. crReportDocument.PrintOptions.PaperSize = PaperSize.PaperA4
    38.  
    39.  
    40. CrystalReportViewer1.DisplayGroupTree = False
    41.  
    42. CrystalReportViewer1.Zoom(100)
    43. ''crReportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
    44. ''crReportDocument.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
    45. ''crReportDocument.Export()
    46. ''CrystalReportViewer1.ExportReport()
    47.  
    48. CrystalReportViewer1.ReportSource = crReportDocument
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Controlling report results thru VB.Net???

    Thanks Asgorath!!!
    Blake

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Controlling report results thru VB.Net???

    Was also wondering if it's possible to use VB code to access each Control on a CR Report, ie; labels, textboxes, etc.
    Blake

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Controlling report results thru VB.Net???

    I'm trying to use the code in Post #2 on a new Form with a CR Viewer control placed on the form. When I try to insert the statement:

    VB Code:
    1. Dim crReportDocument as New CrystalReport1

    Intellisense doesn't prompt me for CrystalReport1. I've copied the sample as you have it upto the point where I insert the above Dim statement.

    What am I missing?

    Thanks,
    Blake

  6. #6
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Controlling report results thru VB.Net???

    Quote Originally Posted by blakemckenna
    I'm trying to use the code in Post #2 on a new Form with a CR Viewer control placed on the form. When I try to insert the statement:

    VB Code:
    1. Dim crReportDocument as New CrystalReport1

    Intellisense doesn't prompt me for CrystalReport1. I've copied the sample as you have it upto the point where I insert the above Dim statement.

    What am I missing?

    Thanks,
    You need to replace CrystalReport1 with the name of report you have created.
    "The dark side clouds everything. Impossible to see the future is."

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Controlling report results thru VB.Net???

    got it...Thanks! One more thing....can I control the entire report thru VB.Net. In other words, all the controls that I have on my report, ie; textboxes, labels, etc. Can I pass them values via my VB Code?
    Blake

  8. #8
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Controlling report results thru VB.Net???

    This is how i change the text of 2 textboxes on the report, called text3 and text5.
    VB Code:
    1. Dim crreportobject As CrystalDecisions.CrystalReports.Engine.ReportObject
    2.                     For Each crreportobject In crReportDocument.ReportDefinition.ReportObjects
    3.                         If TypeOf (crreportobject) Is CrystalDecisions.CrystalReports.Engine.TextObject Then
    4.                             Dim crtextobject As CrystalDecisions.CrystalReports.Engine.TextObject = DirectCast(crreportobject, CrystalDecisions.CrystalReports.Engine.TextObject)
    5.                             If crreportobject.Name.TrimEnd = "Text3" Then
    6.                                 crtextobject.Text = "TEXT"
    7.                             End If
    8.                             If crreportobject.Name.TrimEnd = "Text5" Then
    9.                                 crtextobject.Text = "TEXT"
    10.                             End If
    11.                         End If
    12.                     Next
    "The dark side clouds everything. Impossible to see the future is."

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Controlling report results thru VB.Net???

    that's what I'm lookin' for....Thanks Asgorath!
    Blake

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