How you do this depends on the type of variable you are trying to read. If the variable in the Report is not based on an object from a data provider, you can use the Evaluate method of the BODocuments class to obtain it’t value.
For example:
If in the reporter module we created a variable called “emails” with the definition of “addr1@email.com;addr2@email.com” (Notice not even a leading “=”, making this variable always have a constant value!).
In the ReportScript, we can then do the following to display the value in a message box (obviously, you would probably want to do more than that in your real script!):
Sub Main
Dim EmailAddrs as String
EmailAddrs = ActiveDocument.Evaluate(“=”) MsgBox EmailAddrs
End Sub
The Evaluate method will simply take an argument that is a Reporter Module formula and evaluate it (based on the currently active document in this case).
It gets more complicated if you want to use an object variable (a variable that is part of a data provider in the document). The evaluate method will not work in this case, since a variable that is based on a data provider can hold different values for each row returned by the data provider, the script example above will fail with a #MULTIVALUE error at runtime. To read the values from a data provider variable, you can try the following example:
In the document, let assume (for this example) that you had 1 data provider with an object called “Email Address” in the query. If we wanted to read that variable and manipulate the strings returned for each row of the result set, you can do something like this in ReportScript (again, this is a somewhat simplistic example, but hopefully it will get you started):
Sub Main
’ Set up variable for Business Objects Classes Dim dp as BODataProvider
Dim colm as BOColumn
Dim data as Variant
Dim report as BOReport
’ Counter variables
Dim x as integer
’ Assumes that we want the first data provider on this document, you can point it at any
’ data provider you want …
set dp=ActiveDocument.DataProviders.Item(1)
’ assign the BOColumn variable to the column (object) named “Email Address”
set colm=dp.Columns.Item(“Email Address”)
’ Loop for each record, the count property of the column class will be equal to the number
’ of values (in this case should be the number of rows returned by the data provider)
for x=1 to colm.count
’ Read the value, will return the value as a string if “Email Address” is a character object
set data=colm.item(x)
’ Now that you have the data contained in the column, you can do what ever you want with it
’ I’m just going to display it in a message box
msgbox data
next x
End Sub
Is it possible to get a variable from a report? Application.Variables.Item(“variable name”) doesn’t work for some reason.
I want to set a list of email address to send out a report in the report itself.
hans
hans kingma
unisource carrier services
industriestrasse 21
8403 wallisellen
switzerland
phone: +41 1 839 32 65
fax: +41 1 877 4490
Pls report bounces in response to postings to BUSOB-L-Request@listserv.aol.com
Web archives (9am-5pm ET only): listserv.aol.com/archives/busob-l.html
OR search: Mail to listserv@listserv.aol.com, ‘search a_phrase in BUSOB-L’
Unsubscribe: Mail to listserv@listserv.aol.com, ‘unsubscribe BUSOB-L’
Listserv Archives (BOB member since 2002-06-25)