Friday, February 24, 2012

Custom Code - Reference Report Objects

Hi,
Can anyone point me in the right direction on how to reference report objects in a custom sub or function. For example if I want to assign a value to a report parameter or a textbox
public Sub SetDepth()
Parameters!test.Value = 2
ReportItems!Textbox23.value = "test"
end sub
I've tried really simle stuff like below but i get the following error [BC30469] Reference to a non-shared member requires an object reference.
Cheers
KevinYou can pass in the Parameters or ReportItems collection as an argument to
your function. Note you can't change the values of parameters/textboxes
though - they are read-only.
Fang Wang (MSFT)
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Kevin Wilson" <KevinWilson@.discussions.microsoft.com> wrote in message
news:E136C0ED-9890-4315-8455-14687D66FB24@.microsoft.com...
> Hi,
> Can anyone point me in the right direction on how to reference report
objects in a custom sub or function. For example if I want to assign a value
to a report parameter or a textbox
> public Sub SetDepth()
> Parameters!test.Value = 2
> ReportItems!Textbox23.value = "test"
> end sub
> I've tried really simle stuff like below but i get the following error
[BC30469] Reference to a non-shared member requires an object reference.
> Cheers
> Kevin|||How do you do this?
"Fang Wang (MSFT)" wrote:
> You can pass in the Parameters or ReportItems collection as an argument to
> your function. Note you can't change the values of parameters/textboxes
> though - they are read-only.
> Fang Wang (MSFT)
> Microsoft SQL Server Reporting Services
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "Kevin Wilson" <KevinWilson@.discussions.microsoft.com> wrote in message
> news:E136C0ED-9890-4315-8455-14687D66FB24@.microsoft.com...
> > Hi,
> > Can anyone point me in the right direction on how to reference report
> objects in a custom sub or function. For example if I want to assign a value
> to a report parameter or a textbox
> >
> > public Sub SetDepth()
> > Parameters!test.Value = 2
> > ReportItems!Textbox23.value = "test"
> > end sub
> >
> > I've tried really simle stuff like below but i get the following error
> [BC30469] Reference to a non-shared member requires an object reference.
> >
> > Cheers
> > Kevin
>
>|||For example if you want to calculate average sales. You have two fields
Number of Units and Sales in dollars.
You can write custom code as below:
Public Function GetAvg(ByVal NoOfUnits As Integer, ByVal TotalSales As
Decimal) As Decimal
Dim ReturnValue As Decimal
ReturnValue = 0
If NoOfUnits <> 0 Then
ReturnValue = TotalSales/NoOfUnits
End If
Return ReturnValue
End
In your table cell you can write expression as:
Code.GetAvg(Fields!Units.Value, Fields!Sales.Value)
When you preview the report, you will see the calculated average value in
that cell.
I hope this helps.
"Tanya" <Tanya@.discussions.microsoft.com> wrote in message
news:68055C09-D38E-4CDA-990C-CD4641594E33@.microsoft.com...
> How do you do this?
> "Fang Wang (MSFT)" wrote:
>> You can pass in the Parameters or ReportItems collection as an argument
>> to
>> your function. Note you can't change the values of parameters/textboxes
>> though - they are read-only.
>> Fang Wang (MSFT)
>> Microsoft SQL Server Reporting Services
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> "Kevin Wilson" <KevinWilson@.discussions.microsoft.com> wrote in message
>> news:E136C0ED-9890-4315-8455-14687D66FB24@.microsoft.com...
>> > Hi,
>> > Can anyone point me in the right direction on how to reference report
>> objects in a custom sub or function. For example if I want to assign a
>> value
>> to a report parameter or a textbox
>> >
>> > public Sub SetDepth()
>> > Parameters!test.Value = 2
>> > ReportItems!Textbox23.value = "test"
>> > end sub
>> >
>> > I've tried really simle stuff like below but i get the following error
>> [BC30469] Reference to a non-shared member requires an object reference.
>> >
>> > Cheers
>> > Kevin
>>

No comments:

Post a Comment