VB : Print Single Record from Database using Crystal Report (Using Parameter)

  • 0
Form1 : Code
Private Sub printbtn_Click(sender As System.Object, e As System.EventArgs) Handles printbtn.Click
      Dim f2 As New Form2()
      f2.txtinF2.Text = Me.txtinF1.Text
End Sub
Form 2 : Code
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Private Sub Form2_Load(sender As Object, e As System.EventArgs) Handles Me.Load
      Dim cryRpt As New ReportDocument cryRpt.Load("C:\ProjectFile\Document\Print\printdocument.rpt")       Dim crParameterFieldDefinitions As ParameterFieldDefinitions
      Dim crParameterFieldDefinition As ParameterFieldDefinition
      Dim crParameterValues As New ParameterValues
      Dim crParameterDiscreteValue As New ParameterDiscreteValue
      crParameterDiscreteValue.Value = TextBox1.Text
      crParameterFieldDefinitions = _
      crParameterFieldDefinition = _
      crParameterFieldDefinitions.Item("appname") 'Set this parameter in Crystal Report (Refer here)
      crParameterValues = crParameterFieldDefinition.CurrentValues


      CrystalReportViewer1.ReportSource = cryRpt
End Sub

That is all. You can even export the current document into PDF, CSV, Excel, Word, RTf, and XML by click on the Export Report icon on the very left of CrystalReportViewer.Good luck! :)

No comments: