none
build error "There is an error on line 1 of custom code: [BC30451] 'MyVar' is not declared" in local report rdlc in VS 2013 RRS feed

  • Question

  • Microsoft Visual Studio Professional 2013
    Version 12.0.30110.00 Update 1
    Microsoft .NET Framework
    Version 4.5.51641

    Application is winform, target cpu x86, development system is server 2012 R2 datacenter edition.

    Code behind snippet as follows:

    Dim ssnValue = "Redacted"
    Dim ssnparm As ReportParameter = New ReportParameter("ssnparm", ssnValue)
    Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {ssnparm})
    Dim bytes As Byte() = Me.ReportViewer1.LocalReport.Render("PDF", deviceInfo, mimeType, _encoding, extension, streamids, warnings)

    added parameter name ssnparm, data type text, available values = none, default values = none
    displays as [@]ssnparm in report data window

    report textbox expression category parameters displays Item: <All>, Values: ssnparm, set expression as follows:
    =Parameters!ssnparm.Value

    When we build we get the following error:
    Error 1 There is an error on line 1 of custom code: [BC30451] 'MyVar' is not declared. It may be inaccessible due to its protection level.

    Double clicking on the error text opens report1.rdlc and we do a find on MyVar and find this generated code in the XML file:

    <ReportParameters>
        <ReportParameter Name="ssnparm">
          <DataType>String</DataType>
          <Prompt>ReportParameter1</Prompt>
        </ReportParameter>
      </ReportParameters>
      <Code>Public Function initSSN( ByVal var as String)
           MyVar = ssnparm
     End Function</Code>

    We are running a local report to print to pdf bypassing print preview. So the requirement is not to prompt for the parameter. This report ran displaying the social security number value from the database before we tried to do conditional processing in this application. If the user wants to redact the ssn we want to replace the text value with text ("Redacted") that replaces the ssn value from the column. We collect this choice to redact or not from the user in a text box on the winform.

    Nowhere do we code MyVar and this is generated code from the build so we are lost as to where to begin to resolve this issue. Can anyone help with this error?

    Thanks.

    Bruce




    • Edited by Bmayfield Wednesday, July 23, 2014 4:54 PM
    Wednesday, July 23, 2014 4:02 PM

Answers

  • Problem Solved.

    The MyVar in the function initSSN was NOT generated by Report Builder. We must have tried a suggestion from a Google search by placing the public function initSSN into the custom code section of the Report Properties Page off of the VS main menu. Once we deleted that custom code and rebuilt the application, the parameter replaced the value received from the database.

    Thanks.

    Bruce


    • Marked as answer by Bmayfield Thursday, July 24, 2014 4:09 PM
    • Edited by Bmayfield Thursday, July 24, 2014 4:10 PM
    Thursday, July 24, 2014 4:09 PM