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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Broadcast Agent and VBA

Status
Not open for further replies.

Fezbro

Technical User
Jul 9, 2002
17
AU
We run the following VBA code following the refresh of a document on Broadcast Agent. The idea is for Broadcast agent to attatch the saved file to an email and send it.

Private Sub Document_AfterRefresh()

'File Split
Dim MyDoc As busobj.Document
Dim MyRpt As busobj.Report
Dim MyFilterVar As DocumentVariable
Dim MyFilterChoices As Variant
Dim i, intNumChoices As Integer
Dim StrNextValue As String

Set MyDoc = Application.Documents(1)
Set MyRpt = ActiveReport
Set MyFilterVar = MyDoc.DocumentVariables("Division")
intNumChoices = UBound(MyFilterVar.Values(boUniqueValues))
MyFilterChoices = MyFilterVar.Values(boUniqueValues)

'Open and Create Email
Dim Session As Object
Dim DB As Object
Set Session = CreateObject("Notes.Notessession")
Set DB = Session.GETDATABASE("", "")
Call DB.OPENMAIL
Set Doc = DB.CREATEDOCUMENT
Doc.Form = "Main Topic"
Doc.Subject = "Other Force Crimes"
Set rtitem = Doc.CREATERICHTEXTITEM("Body")


'Loop to Create files and attatch to email
For i = 1 To intNumChoices
StrNextValue = MyFilterChoices(i)
MyRpt.AddComplexFilter MyFilterVar, &quot;=<Division>=&quot; & &quot;&quot;&quot;&quot; & StrNextValue & &quot;&quot;&quot;&quot;
MyRpt.ForceCompute
MyRpt.ExportAsRtf (&quot;C:\temp\NPC&quot; & StrNextValue & &quot;.rtf&quot;)
Set Object = rtitem.EMBEDOBJECT(1454, &quot;&quot;, &quot;C:\temp\NPC&quot; & StrNextValue & &quot;.rtf&quot;, &quot;&quot;)
Next i

'Send Email
Call Doc.Send(True, &quot;EMAIL ADDRESS&quot;)
DB.Close
Session.Close
Set DB = Nothing
Set Session = Nothing

End Sub


The following message comes up in the console: -
Error: &quot;(303) Error with no ErrorHandler with BreAKOnVBAError=False&quot;

Any ideas as to what might be wrong? The VBA runs fine when done from a desktop.
 
That's the error reported when an error has raised in your code, but BA does not report which error has raised. Test and debug the code interactively in your computer to know what happens.

A possible source of error is considering always [tt]MyFilterVar.Values(boUniqueValues)[/tt] as an array. The [tt]DocumentVariable.Values()[/tt] method help explains that:
[ul][li]When there's no values, it returns [tt]Empty[/tt].[/li]
[li]When there's only a value, it returns the value.[/li]
[li]When there's more than a value, it returns an array.[/li][/ul]
You should check the value returned with the [tt]IsEmpty()[/tt] and [tt]IsArray()[/tt] functions to know how to retrieve the values.

You call [tt]AddComplexFilter[/tt] repeatedly with the same variable. Are you sure you can do that? Don't you need to remove the filter first, or accessing the existent filter to modify it?

Other sources of error could be:
[ul][li][tt]Notes[/tt] libray access (I don't know it).[/li]
[li]Can't write to [tt]C:\temp\[/tt] or it does not exist.[/li][/ul]
I recommend you to catch errors and treat them. You could register the error in a log file to know what happened when an error occurs:
[ul][li]At the begining of the macro add:
[tt]On Error Goto AnError[/tt][/li]
[li]At the end of the macro add:
[tt]Exit Sub
AnError:
LogError &quot;While sending Notes messages: &quot; & Err.Description[/tt][/li]
[li]Create a new Procedure:
[tt]Sub LogError (Text as String)
On Error Resume Next
Dim FileNo As Integer
FileNo = FreeFile
Open &quot;C:\temp\SendNotesMessages.log&quot; For Append As FileNo
Print FileNo, Now & &quot; &quot; & ActiveDocument.Name & &quot;: &quot; & Text
Close FileNo
End Sub[/tt][/li][/ul]
I'v noted that you use [tt]Application.Documents(1)[/tt] to refer to the active document. Why don't you simply use [tt]ActiveDocument[/tt]? You could use [tt]Me[/tt] also, since you are inside the [tt]AfterRefresh[/tt] event of the [tt]Document[/tt] object.
 
The code works perfectly on my PC. Does anyone know what the settings for in DCOM for the BCA on the server should be?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top