Export (0) Print
Expand All
5 out of 6 rated this helpful - Rate this topic

Global Collections for Expressions in ReportViewer Reports 

Expressions that you write for report definitions that are processed in ReportViewer controls can include references to global object collections. There are five global object collections that you can use: Fields, Globals, Parameters, ReportItems, and User. To access these collections, you can use standard Visual Basic collection syntax. Examples of this syntax are as follows:

  • Collection!ObjectName

    =User!Language

  • Collection.Item("ObjectName")

    =User.Item("Language")

  • Collection("ObjectName")

    =User("Language")

You can also use property syntax to access items in the Globals and User collections. An example of this is as follows:

  • Collection.ObjectName

    =Globals.PageNumber

Members of the Globals and Users collections return variants. If you want to use a global variable in an expression that requires a specific data type, you must first cast the variable. For example, CDate(Globals!ExecutionTime).

Fields

The Fields collection contains the fields within the current data source. Fields are typically used to display data in text boxes in a report, but they can also be used in other report items, properties, and functions. Items within the Fields collection have two properties, Value and IsMissing. The Value property returns the value that was retrieved for the field in the data source. The IsMissing property indicates whether the field exists in the data source. This is useful for queries that return variable sets of fields. The Value property of missing fields is Null.

The most common syntax for accessing a field object is property syntax, for example, Fields!Product.Value. You can also use the collection syntax described above. Some data sources provide additional properties for a field. You can access these properties using the collection syntax. If the data source does not support the property, or the field is not found when the query is executed, the value for the property is Null for properties of type String and Object, and zero for properties of type Integer.

A report contains one virtual Fields collection for each data source in the report. Fields must be unique within a collection, but the same field name can exist in multiple collections. When referring to a field within a data region, the data table or Business object for the data region determines which collection is used. When referring to a field within an aggregate expression, the data source for the scope determines which collection is used.

Globals

The Globals collection contains the global variables for the report. The following table describes the members of the Globals collection.

Member Type Description

ExecutionTime

DateTime

The date and time that the report began to run.

PageNumber

Integer

The current page number. Can be used only in page header and footer.

ReportFolder

String

The full path to the folder containing the report. This does not include the report server URL. This member only applies to server reports.

ReportName

String

The name of the report as it is stored in the report server database. This member only applies to server reports.

ReportServerUrl

String

The URL of the report server on which the report is being run. This member only applies to server reports.

TotalPages

Integer

The total number of pages in the report. Can be used only in page header and footer.

Examples of global variables are as follows:

  • This expression, placed in a text box in the footer of a report, provides page number and total pages in the report.

    =Globals.PageNumber & " of " & Globals.TotalPages
    
  • This expression provides the name of the report and the time it was run. The time is formatted with the .NET Framework formatting string for short date.

    =Globals.ReportName & ", dated " & Format(Globals.ExecutionTime, "d")
    

Parameters

The Parameters collection contains the report parameters within the report. Parameters can be used in filters or in other functions that alter the report appearance based on the parameter. Items within the Parameters collection have two properties, Value and Label. The Value property returns the value for the parameter, for example, EmployeeID. The Label property returns the user-friendly label for the parameter, for example, EmployeeName. If no label is specified, the value of the Label property is the same as the Value property. If more than one label is associated with the same value, the first matching label is used. Parameters can be accessed through either the property syntax or the collection syntax.

ReportItems

The ReportItems collection contains the text boxes within the report. Items within the ReportItems collection have only one property: Value. The value for a ReportItems item can be used to display or calculate data from another field in the report. To access the value of the current text box, use Me.Value or simply Value. Me.Value and Value cannot be used inside aggregate functions. Use the full syntax to access the value of a text box from within one of these functions.

An example of a report item expression is as follows:

  • This expression, placed in a text box, displays the value of a text box named Textbox1.

    =ReportItems!Textbox1.Value
    

User

The User collection contains data for the user that is running the report. The following table describes the members of the User collection.

Member Type Description

Language

String

The language ID of the user running the report.

UserID

String

The ID of the user running the report.

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.