How do I pass a variable value to a TextBox inside a Header or Footer in the ReportViewer... with VB

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span>This is has been very frustrating and should not take anyone several days to figure out IMO. All the examples I can find are either outdated, do not seem to work or they are for C#. Please help with VB 2010 Pro...
<span>Ive tried several things but heres one to give you an idea...
<span>From the Report1.rdlc form I clicked... Report > Report Properties went to Variables clicked Add then entered the name "MyTitle" then clicked OK.

<span>Then I went to report (rdlc file) and added a textbox named "MyTitleBox" right clicked on the textbox and choose Expression, then went to Variables and double clicked on "MyTitle" and it entered "<span style="font-family:Consolas; font-size:9.5pt =Variables!MyTitle.Value"
<span>Then I clicked OK.
<span>Then in the PrintReport1_Load<span> ... <span> I put the following...
<span><span> <span style="color:blue; font-family:Consolas; font-size:9.5pt Dim<span style="font-family:Consolas; font-size:9.5pt ReportParameter1
<span style="color:blue As <span style="color:blue String = <span style="color:#a31515
"My Text here"
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim Param(0) <span style="color:blue As
<span style="color:#2b91af ReportParameter<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
Param(0) = <span style="color:blue New <span style="color:#2b91af
ReportParameter(<span style="color:#a31515 "ReportParameter1", MyTitleBox.Text)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Me.ReportViewer1.LocalReport.SetParameters(Param)<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Me.ReportViewer1.RefreshReport()
<span style="color:blue; font-family:Consolas; font-size:9.5pt Try
<span style="font-family:Consolas; font-size:9.5pt <span> <span> <span style="color:blue Me.KeyListTableAdapter.Fill(<span style="color:blue Me.KeyListDatabaseDataSet.KeyList)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Me.ReportViewer1.RefreshReport()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Me.ReportViewer1.SetDisplayMode(<span style="color:#2b91af DisplayMode.PrintLayout)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Catch ex <span style="color:blue As
<span style="color:#2b91af Exception
<span style="font-family:Consolas; font-size:9.5pt <span>
MsgBox(ErrorToString)
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue Try
<span>
<span>Then run it and I get the following error... on this line...
<span style="font-family:Consolas; font-size:9.5pt Param(0) = <span style="color:blue
New <span style="color:#2b91af ReportParameter(<span style="color:#a31515 "ReportParameter1", MyTitleBox.Text)

<span>System.NullReferenceException was unhandled<br/>
<span><span> Message=Object reference not set to an instance of an object.
<span>
<span>The report part of this works fine I want to take input from the user in the program and pass it to the textbox in the report header.

<span>I also tried something like this...
<span style="color:blue; font-family:Consolas; font-size:9.5pt Dim<span style="font-family:Consolas; font-size:9.5pt strPublicString
<span style="color:blue As <span style="color:blue String = <span style="color:#a31515
"My Text"
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue With ReportViewer1<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
.LocalReport.ReportPath = <span style="color:#a31515 "Report1.rdlc"<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim lpar <span style="color:blue As
<span style="color:blue New <span style="color:#2b91af ReportParameter(<span style="color:#a31515 "MyPar", strPublicString)<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim lpar1(0) <span style="color:blue As
<span style="color:#2b91af ReportParameter<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
lpar1(0) = lpar<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
.LocalReport.SetParameters(lpar1)<br/>
<span style="font-family:Consolas; font-size:9.5pt <span>
.LocalReport.Refresh()
<span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue With
<span>And got the following error...
<span>Microsoft.Reporting.WinForms.LocalProcessingException was unhandled
<span><span> Message=An error occurred during local report processing.

Anyone know tha answer?? Thanks


View the full article
 
Back
Top