Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to add another variable to this code

Status
Not open for further replies.

funkmonsteruk

IS-IT--Management
Feb 8, 2002
210
0
0
GB
I've been given this code to get a Business Objects report to go through all available variables in a particular field, filter the report by that variable and save the output to a file whose name is based on the variable.

It works fine but i also need to incorporate a stage to e-mail the report to a third party based on another field in the report.

I've managed to sort out the e-mail code but i need to get VBA to insert an e-mail address which is linked to the filter variable, my guess is that i just need to add another variable and insert some more code (a very general solution) - the e-mail field in the report is called "AFSMEMail". The code is as follows:

Sub FilterAndExport()

Dim mydoc As Document
Dim myrpt As Report
Dim myFilterVar As DocumentVariable

Dim i, intNumChoices As Integer
Dim myFilterChoices As Variant
Dim strNextValue As String

Dim Maildb As Object 'the mail database
Dim username As String
Dim maildbname As String
Dim maildoc As Object
Dim attachme As Object
Dim session As Object
Dim embedobject As Object
Dim mytime As String
Dim recipient As String
Dim subject As String
Dim attachment As String
Dim BodyText As String

' Active (open) Document
Set mydoc = Application.Documents.Item(1)

' Active (with focus) Report
Set myrpt = mydoc.Reports.Item(1)

' Put your variable (or query object) here
Set myFilterVar = mydoc.DocumentVariables("account type")

' find out how many resort values there are
intNumChoices = UBound(myFilterVar.Values(boUniqueValues))

' collect the number of choices in a variant variable
myFilterChoices = myFilterVar.Values(boUniqueValues)

For i = 1 To intNumChoices

' Get the variable value
strNextValue = myFilterChoices(i)

' build filter
myrpt.AddComplexFilter myFilterVar, &quot;=<account type> = &quot; & &quot;&quot;&quot;&quot; & strNextValue & &quot;&quot;&quot;&quot;

' recompute the report
myrpt.ForceCompute

' now export to desired format, using the filter value as part of the name
myrpt.ExportAsPDF (&quot;F:\MI\&quot; + strNextValue)

recipient = asmemail
subject = &quot;PSM Diary&quot;
attachment = &quot;F:\MI\&quot; & strNextValue & &quot;.pdf&quot;
BodyText = &quot;Diary&quot;
Set session = CreateObject(&quot;Notes.NotesSession&quot;)
username = session.username

Set Maildb = session.GETDATABASE(&quot;&quot;, maildbname)
If Maildb.ISOPEN = True Then

Else
Maildb.OPENMAIL
End If
Set maildoc = Maildb.CREATEDOCUMENT
maildoc.Form = &quot;Memo&quot;
maildoc.sendto = recipient
maildoc.subject = subject
maildoc.Body = BodyText


If attachment <> &quot;&quot; Then
Set attachme = maildoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set embedobject = attachme.embedobject(1454, &quot;&quot;, attachment, &quot;Attachment&quot;)


End If

maildoc.PostedDate = Now()
maildoc.Send 0, recipient

Set Maildb = Nothing
Set maildoc = Nothing
Set attachme = Nothing
Set session = Nothing

MsgBox &quot;Mail sent to&quot; & recipient & &quot;re:&quot; & subject


Next i

' now, unless I can find a RemoveComplexFilter function, this line is used
' to invoke a filter that is always true.

myrpt.AddComplexFilter myFilterVar, &quot;=(1=1)&quot;
myrpt.ForceCompute

End Sub

Any ideas???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top