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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RayboneAuthor Commented:
Edited text of question.
Create an agent that will run the action you desire with LotusScript.  With that action, use:

Dim session as New NotesSession
Dim db as NotesDatabase
Dim collection as NotesDocumentCollection

Set db = session.CurrentDatabase
Set collection= db.UnprocessedDocuments
'this will grab all selected documents in the view if your agent is selected to run on selected documents
'next process all the documents anyway you wish

If I had to give you steps...
1) Create an agent for the action you desire
2) Create an action button in the view for the corepsonding action
3) call that action w/ @Command([ToolsRunMacro]; agentName) in the action button

--Good luck; I hope this answered your question

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RayboneAuthor Commented:
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.
RayboneAuthor Commented:
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.


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.application.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              
          Set MyDoc = Nothing
          Set Application = Nothing
          Continue = False  
     End If
     Exit Sub
     Exit Sub
     Messagebox "Error" & Str(Err) & ": " & Error$
     Resume Next

End Sub

Thanks Again,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.