Using Code Function in Table Group?

  • I defined the following Code Function to determine the name of the field I want to use to Group my table by:

    Function GroupField(ByVal GroupName as String) as String

    Select Case lcase(GroupName)

    Case "project mailing type"

    Return "Proj_Mailing_Type_DESC"

    Case "fund partner"

    Return "Fund_Partner_NM"

    Case "project name"

    Return "Proj_NM"

    Case Else

    Return "Proj_Mailing_Type_DESC"

    End Select

    End Function

    GroupName is a Report Parameter. I have the data in a table in the report and I want to group by a different field based on the GroupName. I edited the Grouping for my table to use:

    =Fields(Code.GroupField(Parameters!GroupName.Value)).Value

    I also display this value in a Textbox in the page header and I display the results of:

    =Code.GroupField(Parameters!cGroup1Field.Value)

    in a Textbox. When I enter "Project Mailing Type" as the GroupName I see the correct value in the first Textbox and the correct DB Field Name in the second Textbox but the data is grouped by the Proj_NM field as if I entered "Project Name". If I enter "Fund Partner" or "Project Name" I get the correct info displayed and the table is grouped correctly.

    Any ideas?

     

  • I have to admit I have never tried what you are doing, but I am not sure it is possible either. I think you are just getting lucky with the 2 that "work".

    I don't think you can replace part of an object name with a string. Have you done this before?

  • This is the process for dynamic grouping that is documented in several places. I've never done it before but it is well documented.

    Do you have another approach to dynamic grouping?

     

  • Have you tried changing the order of your case statements to see if the results change?

    Is it also possible that you're getting a default value assigned because of a step / piece missing?

  • I recreated the report from scratch and now it works. I must have mucked up the table/grouping definitions somehow the first time through. RS isn't very forgiving....

     

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply