none
Visual Studio 2012: How to insert VBA code at the Application or Project Level RRS feed

  • Question

  • Version:  Visual Studio 2012

    Problem:  I want to insert the following VBA code into Visual Studio and don't know how to do it.  Also I don't know if I should insert this at the Application or Project Level.  I need this code to streamline the "Divide by Zero" error when working in SSRS projects.  I looked on-line and it was mentioned that the Developer Ribbon was needed and to get the Developer Ribbon I would need to install Office Developer Tools for Visual Studio 2012.  I'm new to Visual Studio, but have been programming in VBA for a long-time.  Any advise would be greatly appreciated.

    Divide by Zero Code:

    In the Menu; go to Report > Report Properties > Code and paste the code bellow

    Public Function Quotient(ByVal numerator As Decimal, denominator As Decimal) As Decimal
            If denominator = 0 Then
                Return 0
            Else
                Return numerator / denominator
            End If
        End Function

    To call the function go to the the Textbox expression and type:

    =Code.Quotient(SUM(fields!FieldName.Value),SUM(Fields!FieldName2.Value))

     in this case I am putting the formula at the Group level so I am using sum. Otherwise it would be:

    =Code.Quotient(fields!FieldName.Value,Fields!FieldName2.Value)

    From <http://williameduardo.com/development/ssrs/ssrs-divide-by-zero-error/>


    Bob Sutor

    Thursday, October 8, 2015 6:13 PM

Answers

  • Hi ConstPM,

    In Reporting Services, we can embed custom code in the report. The code is added at the report level. For more information, please refer to this article: Add Code to a Report (SSRS).

    In your scenario, the code which you have found in the article can be added into the report. In report design surface, open Report->Report Properties->Code tab. Please refer to screenshots below:


    If you have any question, please feel free to ask.

    Best regards,
    Qiuyun Yu


    Qiuyun Yu
    TechNet Community Support


    • Marked as answer by ConstPM Monday, October 12, 2015 3:20 PM
    Monday, October 12, 2015 7:03 AM
    Moderator

All replies

  • Hi Bob,

    Since this issue is related to the SSRS project development, I help you move this case to the SSRS forum for dedicated support.

    Thanks,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 12, 2015 3:36 AM
  • Hi ConstPM,

    In Reporting Services, we can embed custom code in the report. The code is added at the report level. For more information, please refer to this article: Add Code to a Report (SSRS).

    In your scenario, the code which you have found in the article can be added into the report. In report design surface, open Report->Report Properties->Code tab. Please refer to screenshots below:


    If you have any question, please feel free to ask.

    Best regards,
    Qiuyun Yu


    Qiuyun Yu
    TechNet Community Support


    • Marked as answer by ConstPM Monday, October 12, 2015 3:20 PM
    Monday, October 12, 2015 7:03 AM
    Moderator
  • I wouldn't have thought about looking in Report Properties.  Thanks!

    Bob Sutor

    Monday, October 12, 2015 3:20 PM