I have this problem where crystal report is prompting me to enter a value even though I already pass the value from textbox in the vb form.
This is how I create the parameter:
As you can see, I named the parameter NAME.
And here is my code for passing the value from TextBox to parameter NAME in crystal report:
Private Sub indi_print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles indi_print.Click
Dim locatorReport As New report_viewer
Dim rptDoc As CrystalReports.Engine.ReportDocument
rptDoc = New indi_locatorReport 'indi_locatorReport is the Crystal Report
rptDoc.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLegal
rptDoc.PrintOptions.ApplyPageMargins(New CrystalDecisions.Shared.PageMargins(200, 200, 100, 1500))
rptDoc.SetParameterValue("NAME", name_txtbox.Text)
locatorReport.crptViewer.ReportSource = rptDoc
locatorReport.ShowDialog()
End Sub
When i click the Print Button this is the result:
As you can see Crystal Report prompt me to enter a name. How to fix this?
Try
Dim rptDoc As New indi_locatorReport
rptDoc.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperLegal
rptDoc.PrintOptions.ApplyPageMargins(New CrystalDecisions.Shared.PageMargins(200, 200, 100, 1500))
rptDoc.SetParameterValue("NAME", name_txtbox.Text)
locatorReport.crptViewer.ReportSource = rptDoc
locatorReport.ShowDialog()
I already solved the problem. The problem is whenever the form report_viewer loads, it refreshes the crystal report. It has the Me.crptViewer.RefreshReport() code. I did not notice this because the crystal report viewer created this code.
Related
can you help me i have problem with vb.net language.
I want to call crystal report but can't with the data format in gridview sent via crystalreport. with the following code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim reports As New bpkb_1
reports.SetDataSource(ds.Tables(0))
viewermurabahah.CrystalReportViewer1.ReportSource = reports
viewermurabahah.ShowDialog()
end sub
can you give an example of how the code to call the crystal report file outside of the visual studio vb.net project file?
You can call the load method of the ReportDocument
Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load(<Path to your crystal report file>)
rpt.SetDataSource(<your data table>)
YouReportViewer.ReportSource = rpt
i created a report and trying to load it to a reportviewer manually but not able to get it loaded .
my code
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ReportViewer1.Reset()
Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource
ReportDataSource1.Name = "InvoiceData_DataTable1"
ReportDataSource1.Value = New InvoiceDataTableAdapters.DataTable1TableAdapter().GetData("EBM267")
Me.ReportViewer1.LocalReport.DataSources.Clear()
Me.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource1)
ReportViewer1.LocalReport.ReportEmbeddedResource = "Billmanagement.report.rdlc"
ReportViewer1.RefreshReport()
End Sub
my Dataset name is InvoiceData
DataTable1 has a parameter billno
which i am supplying for demo but not working please let me know why my report is not loading
a blank report with error is comming
"A datasource instance has not been supplied for the datasource DataSet1"
In Billmanagement.report.rdlc you are using an oject with .DataSetName property set as DataSet1: check every Table/List/Matrix in your report.
Form1 has a button1 and a texbox1, when I click button1, form2 will load with crystal report on it and display data that I put on textbox1. Already created Parameters Field crTextBox and put into crystalreport. How can I pass textbox1.text value to crTextBox.
Add the following code inside Form2
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim Report1 As New CrystalReport1
Report1.SetParameterValue("crTextBox", Form1.TextBox1.Text)
CrystalReportViewer1.ReportSource = Report1
End Sub
You have to use a parameter fields of Crystal report for this....
1.Open Field Explorer window in Crystal report.
2.Go to Parameter Fields.
3.Right Click on "Parameter Fields"
Click on "New"
4.In the pop-up window give a Name for your parameter and give its Data Type.Name is mytextBoxValue and Data Type is String.
5.A parameter field[mytextBoxValue] will be added under Parameter Fields...Drag this field to your report and place where you want to show your textbox value.
6.Now in the code behind file write the following code to pass your TextBox value to this Crystal report parameter field.
Dim txtValue As String=TextBox1.Text
Dim myReport As New CrystalReport1
myReport .SetParameterValue("mytextBoxValue", txtValue )
You should write something like:
Dim rpt as New ReportDocument
'rpt.Load("file.rpt") ...
'rpt.SetDatasource() ...
rpt.DataDefinition.FormulaFields.Item("MyFormula").Text = textbox1.text
'this code works fine for me
Dim CrxReport As New cm_Detallado_Partes_vs
Try
Cursor.Current = Cursors.WaitCursor
CrystalReportViewer1.ReportSource = CrxReport
'the formula must be the same as it is used in CR
CrxReport.DataDefinition.RecordSelectionFormula = "{tpresupuesto.codigo} = '18-0004'"
CrystalReportViewer1.ShowExportButton = True
CrystalReportViewer1.ShowPrintButton = True
CrystalReportViewer1.ShowGroupTreeButton = True
CrystalReportViewer1.Zoom(100)
Cursor.Current = Cursors.Default
Catch ex As Exception
MsgBox(ex.ToString & vbCrLf & ex.Message & vbCrLf & ex.StackTrace)
End Try
I got a problem in my vb Project, as from subject its clear that I have a problem in specifying many reports in one report viewer in one form.
It's difficult to create many forms and adding report viewer in each form.
I have more than 100 reports.rdlc and want to show it in one report viewer by choosing multiple options in combobox or different criterias.
If you want the same form window to appear each time you change report in your combobox, just create a new instance of that form every time you go to generate the .rdlc report.
Button1 Click
When you click this button, it will create two reports. One report will be generated from the method YourFirstReport() and the other from YourSecondReport(). Both using the same ReportViewer1 control from the same form using a new instance of rv.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Create instance "rv" of your report viewer form
Dim rv As New frmReportViewer
rv.YourFirstReport()
rv = New frmReportViewer
rv.YourSecondReport()
End Sub
rv.YourFirstReport()
Public Sub YourFirstReport()
ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.YourFirstReportName"
'...
'And so on..
End Sub
rv.YourSecondReport()
Public Sub YourSecondReport()
ReportViewer1.LocalReport.ReportEmbeddedResource = "YourProject.YourSecondReportName"
'...
'And so on..
End Sub
Take my example here, the square in red has a button that generates my frmReportViewer every time I click on it. The green circles demonstrate my reports that pop up. Both these report utilize the same form.
You can create a single ReportViewer and set his property at runtime:
path to rldc file: .LocalReport.ReportPath
report datasources: .LocalReport.DataSources
report parameters: .LocalReport.SetParameters
other property: for example .LocalReport.EnableExternalImages
Then you can .RefreshReport().
Just as tezzo said,
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath = "Report2.rdlc"
ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", CType(d1, DataTable)))
ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WebForms.ReportParameter("ReportCriteria", criteria))
ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WebForms.ReportParameter("FileDate", fileDateString))
ReportViewer1.Visible = True
ReportViewer1.DataBind()
Changing the localreport reportpath to a different reportname is all you really need.
Okay this is what I have so far. I have a form that needs to load a file externally and populate the combobox. I can get that part if I use a button, but I don't want to use a button. I want it to populate when the form loads for the first time. The below code does not accomplish this, it doesn't even try to load it. I put break points in this code but it never breaks. I am thinking that the combobox isn't loaded yet and the program doesn't try.
Any help would be nice.
Private Sub mortCalMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'sets listview values
mortBox.SelectedIndex = 0
Dim rdr As StreamReader = File.OpenText("mortgageTypes.txt")
While Not rdr.EndOfStream
Dim line As String = rdr.ReadLine()
mortBox.Items.Add(line)
End While
rdr.Close()
End Sub
Comment out this line:
'mortBox.SelectedIndex = 0
You can't set the index on an empty list.