Raybone
asked on
Accessing a NotesUIView outside of its events
I need to access the currently selected documents in a view & process them from script via an action button, similar to the way a user can select multiple documents then click Print or Delete.
I know the NotesUIView class contains a Documents property that represents: "All the documents that the current NotesUIView event is working on." This seems to be what I'm after. But the only way to access the NotesUIView class is when it is passed to you via the view events. My button would operate outside of those events. How can I get at the currently selected documents collection? Could I cause one of those events to fire & then handle the NotesUIView.Documents collection? If so, which event is best & how would I trigger it?
TIA
Raybone
I know the NotesUIView class contains a Documents property that represents: "All the documents that the current NotesUIView event is working on." This seems to be what I'm after. But the only way to access the NotesUIView class is when it is passed to you via the view events. My button would operate outside of those events. How can I get at the currently selected documents collection? Could I cause one of those events to fire & then handle the NotesUIView.Documents collection? If so, which event is best & how would I trigger it?
TIA
Raybone
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help. I just figured out a really ugly way to do what I needed:
I created a Shared Folder & Called it Printer. Next I wrote my code to the queryaddtofolder event of the view. The code tests for the Printer folder & if met, processes the docs then sets Continue to False so they don't copy.
I'm going to try your way. It looks a lot cleaner.
I created a Shared Folder & Called it Printer. Next I wrote my code to the queryaddtofolder event of the view. The code tests for the Printer folder & if met, processes the docs then sets Continue to False so they don't copy.
I'm going to try your way. It looks a lot cleaner.
ASKER
Your solution was exactly the way to go!!! Not only was it cleaner, but it allowed me to keep the code I needed to extract & print the attachments in 1 place, then call it via Action Buttons from several views & the form itself. The code always works for the selected document(s), no matter where it's being called from.
Bravo!!!
Just in case anyone's interested, here's the final Print Agent code:
Sub Initialize
On Error Goto ErrorHandler
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim rtitem As Variant
Dim FileName As String
Set db = session.CurrentDatabase ' Get the Selected Doc Collection
Set dc= db.UnprocessedDocuments
If dc.count > 0 Then ' if there are Selected Documents, print them
Set Application = CreateObject("Word.applica tion.8") ' Instantiate Word
For j = 1 To dc.Count
Set doc = dc.GetNthDocument(j)
Set rtitem = Doc.GetFirstItem( "FileToAppend" ) ' Get the File Attachment
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If o.Type = EMBED_ATTACHMENT Then
filename = "C:\Windows\Temp\" + Format(Now,"yyyymmddhhnns" )+ o.Name
Call o.ExtractFile ( filename ) ' Extract it to a file for printing
End If
End Forall
Call Application.Documents.Open (FileName)
Set myDoc = Application.Documents(1)
myDoc.PrintOut (False) ' The false option is for Background & tells Word to wait until action is done to continue code. Prevents the
' Next few lines from killing word before it's done printing.
End If
Next
Application.Quit
Set MyDoc = Nothing
Set Application = Nothing
Continue = False
End If
Exit Sub
ErrorHandler:
Exit Sub
Messagebox "Error" & Str(Err) & ": " & Error$
Resume Next
End Sub
Thanks Again,
Raybone
Bravo!!!
Just in case anyone's interested, here's the final Print Agent code:
Sub Initialize
On Error Goto ErrorHandler
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim rtitem As Variant
Dim FileName As String
Set db = session.CurrentDatabase ' Get the Selected Doc Collection
Set dc= db.UnprocessedDocuments
If dc.count > 0 Then ' if there are Selected Documents, print them
Set Application = CreateObject("Word.applica
For j = 1 To dc.Count
Set doc = dc.GetNthDocument(j)
Set rtitem = Doc.GetFirstItem( "FileToAppend" ) ' Get the File Attachment
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If o.Type = EMBED_ATTACHMENT Then
filename = "C:\Windows\Temp\" + Format(Now,"yyyymmddhhnns"
Call o.ExtractFile ( filename ) ' Extract it to a file for printing
End If
End Forall
Call Application.Documents.Open
Set myDoc = Application.Documents(1)
myDoc.PrintOut (False) ' The false option is for Background & tells Word to wait until action is done to continue code. Prevents the
' Next few lines from killing word before it's done printing.
End If
Next
Application.Quit
Set MyDoc = Nothing
Set Application = Nothing
Continue = False
End If
Exit Sub
ErrorHandler:
Exit Sub
Messagebox "Error" & Str(Err) & ": " & Error$
Resume Next
End Sub
Thanks Again,
Raybone
ASKER